Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN 0.71 Splashscreen.show() not working on iOS #610

Open
Engraulis61 opened this issue Apr 2, 2023 · 11 comments
Open

RN 0.71 Splashscreen.show() not working on iOS #610

Engraulis61 opened this issue Apr 2, 2023 · 11 comments

Comments

@Engraulis61
Copy link

Engraulis61 commented Apr 2, 2023

What react-native-splash-screen version are you using?
3.3.0
What platform does your issue occur on? (Android/iOS/Both)
iOS
i just want to show user splash screen after rnrestart.restart() command. but Splashscreen.show() method not working on iOS.

In older versions of React, I could solve this problem by adding code to the AppDelegate.mm file. However, since the AppDelegate.mm file has changed, I am unable to display the splash screen after using the RNrestart.Restart() command.

I used to use these codes in old versions of React Native:

RCTRootView *rootView = RCTAppSetupDefaultRootView(bridge, @"appname", nil);

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
UIViewController vc = [sb instantiateInitialViewController];
UIView
launchScreenView = vc.view;
launchScreenView.frame = self.window.bounds;
RCTRootView.loadingView = launchScreenView;

Is there anyone who can help with a solution for this problem?

@robwalkerco
Copy link

Duplicate of #606

@Engraulis61
Copy link
Author

I don't think it's the same topic.I tried the code block there, but splashscreen.show() didn't work after RNrestart.Restart().

@a-tokyo
Copy link

a-tokyo commented Apr 6, 2023

Change the code in your AppDelegate.mm to be

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{  
  self.moduleName = @"ProjectName";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};
  
  bool didFinish = [super application:application didFinishLaunchingWithOptions:launchOptions];
  
  [RNSplashScreen show];  // this needs to be called after [super application:application didFinishLaunchingWithOptions:launchOptions];
  
  return didFinish;
}

@Engraulis61
Copy link
Author

Thank you for your help, but this solution did not work.

@a-tokyo
Copy link

a-tokyo commented Apr 6, 2023

If it's blocking your development, I highly recommend switching to this library https://www.npmjs.com/package/react-native-bootsplash - It's way more maintained and I am planing to move to it as well @Engraulis61

@clarissacarcha
Copy link

+1 same issue

@Coffeegerm
Copy link

@a-tokyo Your solution seemed to help in my case thanks! The docs for the package probably should just be updated to reflect this, but the best bet considering this package is largely unmaintained at this point is to move to bootsplash like you suggest.

@arnoldc
Copy link

arnoldc commented Apr 1, 2024

Change the code in your AppDelegate.mm to be

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{  
  self.moduleName = @"ProjectName";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};
  
  bool didFinish = [super application:application didFinishLaunchingWithOptions:launchOptions];
  
  [RNSplashScreen show];  // this needs to be called after [super application:application didFinishLaunchingWithOptions:launchOptions];
  
  return didFinish;
}

this solution still causes white flashes
at 0.71 there is a proper way to do this, see below

Follow guide from the maintainers facebook/react-native#35937 (comment)

At AppDelegate.mm, override createRootViewWithBridge

- (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
                          moduleName:(NSString *)moduleName
                           initProps:(NSDictionary *)initProps
{
  UIView * view = [super createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps];
  
#if RCT_NEW_ARCH_ENABLED
  RCTFabricSurfaceHostingProxyRootView * rootView = (RCTFabricSurfaceHostingProxyRootView *)view;
#else
  RCTRootView * rootView = (RCTRootView *)view;
#endif
  
  // workaround:
  UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
  UIViewController *vc = [sb instantiateInitialViewController];
  rootView.loadingView = vc.view;

  return rootView;
}

ive tested in ios 16 and ios 17 seems working fine now

RicardasN added a commit to flexn-io/renative that referenced this issue May 7, 2024
Based on crazycodeboy/react-native-splash-screen#610 (comment)

It seems to work now when no metro server gets found, but the problem is that it does not work in any other case...
@LasithaOffice
Copy link

Change the code in your AppDelegate.mm to be

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{  
  self.moduleName = @"ProjectName";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};
  
  bool didFinish = [super application:application didFinishLaunchingWithOptions:launchOptions];
  
  [RNSplashScreen show];  // this needs to be called after [super application:application didFinishLaunchingWithOptions:launchOptions];
  
  return didFinish;
}

Worked beautifully

@tvn19113
Copy link

tvn19113 commented Oct 2, 2024

Hi @arnoldc, I tried your solution, and it worked, but I encountered another issue. My splash screen has some custom customizations (such as showing the app version at the bottom). However, when I forced the app to restart, the splash screen appeared, but the customized UI did not show, it just shows app icon in center of the screen.
Do you have any solution for this issue?

@Unich-HieuDT
Copy link

@Engraulis61 Hi. I’m facing the exact same issue as you. Specifically, SplashScreen.show() is not working on iOS. If we use react-native-bootsplash, there is no .show() method. How did you handle this issue? Could you share your solution with me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants