SplashScreen.show(); not working in React Native iOS

420 views Asked by At

I'm having issue with regards to react-native-splash-screen. When I triggered the SplashScreen.show(); in my Home Screen it doesn't work in iOS but in android it is working.

RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];

#if RCT_NEW_ARCH_ENABLED
  _contextContainer = std::make_shared<facebook::react::ContextContainer const>();
  _reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
  _contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
  _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
  bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
#endif

  NSDictionary *initProps = [self prepareInitialProps];
  UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"ProjectName", initProps);

  if (@available(iOS 13.0, *)) {
    rootView.backgroundColor = [UIColor systemBackgroundColor];
  } else {
    rootView.backgroundColor = [UIColor whiteColor];
  }

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

[RNSplashScreen show];

return YES;

I need to re-run the SplashScreen.show(); because RNRestart.Restart() displaying a white scree. Thank you for your help!

1

There are 1 answers

1
Mohd Ehtesham On

for IOS 0.60.0 to newer=>

First step(Download): Run npm i react-native-splash-screen --save cd ios run pod install

Second step : #import "RNSplashScreen.h" // (in AppDelegate.m on top of the code)

Third Step add ->[RNSplashScreen show]; // in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

return YES; }add this line before return

fourth Step : 1- You have to open the xcode And go to the lanchscreen option delete the default text of splashScreen. 2- plaese press add button top of the xcode and search image view after that drag it on the lanchscreen view . 3 - go to the image option and set the image of 1X 2x and 3x png image .(optional- you can add app icon from this state)

4- go back to lanchscreen and add image from right side of the toolbar . 5- App.js

add (import SplashScreen from 'react-native-splash-screen')in the top of the code and add SplashScreen.hide()in useEffect.

now make the build .

I hope it will work.