-
-
Save tawanorg/b2aaf68f6c659760b4bf4a007d5aa9b7 to your computer and use it in GitHub Desktop.
ReactNative iOS Launch Screen No Flash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
// 1. init window | |
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
UIViewController *rootViewController = [UIViewController new]; | |
// 2. backgroundView using LaunchScreen.xib | |
UIView *backgroundView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] firstObject]; | |
backgroundView.frame = self.window.bounds; | |
// 3. ReactNative init | |
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; | |
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation | |
moduleName:@"MyAwesomeApp" | |
initialProperties:nil | |
launchOptions:launchOptions]; | |
// 4. rootView background clear, so our backgroundView can show until ReactNative has fully loaded | |
rootView.backgroundColor = [UIColor clearColor]; | |
// 5. set loadingView to the LaunchScreen.xib view too | |
// explicitly set all frames | |
UIView *launchScreenView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] firstObject]; | |
rootView.frame = self.window.bounds; | |
launchScreenView.frame = self.window.bounds; | |
rootView.loadingView = launchScreenView; | |
// 6. set the backgroundView as main view for the rootViewController (instead of the rootView) | |
rootViewController.view = backgroundView; | |
// 7. show | |
self.window.rootViewController = rootViewController; | |
[self.window makeKeyAndVisible]; | |
// 8. after the window is visible, add the rootView as a subview to your backgroundView | |
[backgroundView addSubview:rootView]; | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment