Just added splash screen for my app, but it seem like it runs not at the first palce.
I mean when i run the app on avd simulator, i still get white screen loading first for milliseconds then splashscreen. ISs there any reason for that or maybe i used the functionality wrong?
This is my loading screen code:
function LoadingScreen ({navigation}) {
setTimeout (() => {
navigation.replace('FirstScreen');
}, 4000);
return (
<ImageBackground style={styles.backgroundContainer} source={splashScreen}/>
);
};
const Stack = createStackNavigator();
const PERSISTENCE_KEY = 'NAVIGATION_STATE';
function App() {
const [isReady, setIsReady] = React.useState(false);
const [initialState, setInitialState] = React.useState();
React.useEffect(() => {
const restoreState = async () => {
try {
const savedStateString = await AsyncStorage.getItem(PERSISTENCE_KEY);
const state = savedStateString ? JSON.parse(savedStateString) : undefined;
if (state !== undefined) {
setInitialState(state);
}
} finally {
setIsReady(true);
}
};
if (!isReady) {
restoreState();
}
}, [isReady]);
if (!isReady) {
return <ImageBackground style={styles.backgroundContainer} source={splashScreen}/>
}
return(
<NavigationContainer
initialState={initialState}
onStateChange={(state) =>
AsyncStorage.setItem(PERSISTENCE_KEY, JSON.stringify(state))
}
>
<Stack.Navigator initialRouteName='SplashScreen' headerMode='none' >
<Stack.Screen name = 'SplashScreen' component={LoadingScreen}/>
<Stack.Screen name ='FirstScreen' component={FirstScreen}/>