Skip to content

Instantly share code, notes, and snippets.

@guillaumemorin
Last active November 8, 2018 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillaumemorin/615668c2a7f6391f45251cc29b9110b7 to your computer and use it in GitHub Desktop.
Save guillaumemorin/615668c2a7f6391f45251cc29b9110b7 to your computer and use it in GitHub Desktop.
react-native-splashscreen-ios.md

in AppDelegate.m

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // ...

  // 1. Load the LaunchScreen from the xib file
  UIView *backgroundView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] firstObject];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation ... ];

  // 2. Set the backgroundColor of the react view to be transparent
  rootView.backgroundColor = [UIColor clearColor];

  // ...

  // 3. Set the backgroundView as main view for the rootViewController (instead of the rootView)
  rootViewController.view = backgroundView;

  [self.window makeKeyAndVisible];

  // 4. After the window is visible, add the rootView as a subview to your backgroundView
  [backgroundView addSubview:rootView];

  // 5. Then make the rootViews frame the same as the backgroundView
  rootView.frame = backgroundView.frame;

  return YES;
}

@end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment