[iOS] respect initial status bar configuration when displaying the launch storyboard
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m
index 37bd4c7..3186cc6 100644
--- a/src/video/uikit/SDL_uikitappdelegate.m
+++ b/src/video/uikit/SDL_uikitappdelegate.m
@@ -33,6 +33,14 @@
#include "../../events/SDL_events_c.h"
+#if !TARGET_OS_TV
+#include <AvailabilityVersions.h>
+
+# ifndef __IPHONE_13_0
+# define __IPHONE_13_0 130000
+# endif
+#endif
+
#ifdef main
#undef main
#endif
@@ -116,6 +124,53 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
return image;
}
+
+@interface SDLLaunchStoryboardViewController : UIViewController
+@property (nonatomic, strong) UIViewController *storyboardViewController;
+- (instancetype)initWithStoryboardViewController:(UIViewController *)storyboardViewController;
+@end
+
+@implementation SDLLaunchStoryboardViewController
+
+- (instancetype)initWithStoryboardViewController:(UIViewController *)storyboardViewController {
+ self = [super init];
+ self.storyboardViewController = storyboardViewController;
+ return self;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ [self addChildViewController:self.storyboardViewController];
+ [self.view addSubview:self.storyboardViewController.view];
+ self.storyboardViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ self.storyboardViewController.view.frame = self.view.bounds;
+ [self.storyboardViewController didMoveToParentViewController:self];
+
+ UIApplication.sharedApplication.statusBarHidden = self.prefersStatusBarHidden;
+ UIApplication.sharedApplication.statusBarStyle = self.preferredStatusBarStyle;
+}
+
+- (BOOL)prefersStatusBarHidden {
+ return [[NSBundle.mainBundle objectForInfoDictionaryKey:@"UIStatusBarHidden"] boolValue];
+}
+
+- (UIStatusBarStyle)preferredStatusBarStyle {
+ NSString *statusBarStyle = [NSBundle.mainBundle objectForInfoDictionaryKey:@"UIStatusBarStyle"];
+ if ([statusBarStyle isEqualToString:@"UIStatusBarStyleLightContent"]) {
+ return UIStatusBarStyleLightContent;
+ }
+#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
+ if (@available(iOS 13.0, *)) {
+ if ([statusBarStyle isEqualToString:@"UIStatusBarStyleDarkContent"]) {
+ return UIStatusBarStyleDarkContent;
+ }
+ }
+#endif
+ return UIStatusBarStyleDefault;
+}
+
+@end
#endif /* !TARGET_OS_TV */
@interface SDLLaunchScreenController ()
@@ -374,7 +429,8 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
* Xcode. We'll try to load it as a storyboard first, as it's more
* modern. */
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:screenname bundle:bundle];
- vc = [storyboard instantiateInitialViewController];
+ __auto_type storyboardVc = [storyboard instantiateInitialViewController];
+ vc = [[SDLLaunchStoryboardViewController alloc] initWithStoryboardViewController:storyboardVc];
}
@catch (NSException *exception) {
/* Do nothing (there's more code to execute below). */