wix / react-native-navigation

A complete native navigation solution for React Native
https://wix.github.io/react-native-navigation/
MIT License
13.04k stars 2.67k forks source link

[V2][Android] Splash screen pops up twice #4974

Closed el-lsan closed 5 years ago

el-lsan commented 5 years ago

Issue Description

I'm trying to show a loading screen (app.loadingScreen in code snippet) while my redux store is being rehydrated, then navigate to my main screen (app.homeScreen in code snippet) But for some reason the splash screen is showing up between my loading component and main component.

Code Snippets and Screenshots

Navigation.events().registerAppLaunchedListener(() => {
  bootstrap();
});

async function bootstrap() {
  // this function is registering all of my screens using Navigation.registerComponentWithRedux
  registerScreens(store, provider);

  // Navigate to loading screen as the first screen of the app
  Navigation.setRoot({
    root: {
      stack: {
        id: 'splash',
        children: [{
          component: {
            name: 'app.loadingScreen',
            options: {
              topBar: {
                drawBehind: true,
                visible: false,
                animate: false,
              },
            },
          },
        }],
      },
    },
  });

  // Loads resources and persist and rehydrate my redux store using redux-persist
  await Promise.all([loadIcons(), persistStore(store)]).then(() => {
   // Navigate to home screen once the store is rehydrated
    Navigation.setRoot({
      root: {
        stack: {
          id: 'root',
          children: [{
            component: {
              name: 'app.homeScreen',
            },
          }],
        },
      },
    });
  });  
}

On Android the splash screen is flashing before the second Navigation.setRoot

RNN ANDROID

However on IOS everything is as expected:

RNN IOS `


Environment

support[bot] commented 5 years ago

We use the issue tracker exclusively for bug reports and feature requests. This issue appears to be a general usage or support question. Instead, please ask a question on Stack Overflow with the react-native-navigation tag.

el-lsan commented 5 years ago

@ItsNoHax I believe this is more like a bug than a question!

dvill03 commented 2 years ago

In android, this happens because a modal is opened before the SplashScreen.hide() condition is met. Basically it shows SplashScreen -> Modal -> SplashScreen -> condition for closing modal -> HomeScreen

Or you can also call SplashScreen.hide() inside right before you render the modal. That should stop the splash screen from showing again after the modal takes over.