Reputation: 3959
After initializing a template "tabs" Expo project, the startup routine for the React Native app looks as follows:
React.useEffect(() => {
async function loadResourcesAndDataAsync() {
try {
SplashScreen.preventAutoHide();
// Load our initial navigation state
setInitialNavigationState(await getInitialState());
// Load fonts
await Font.loadAsync({
...Ionicons.font,
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
});
} catch (e) {
// We might want to provide this error information to an error reporting service
console.warn(e);
} finally {
setLoadingComplete(true);
SplashScreen.hide();
}
}
loadResourcesAndDataAsync();
}, []);
Expo's documentation on making the "splash screen stick around for longer" simply demonstrates:
import { SplashScreen } from 'expo';
SplashScreen.preventAutoHide();
setTimeout(SplashScreen.hide, 5000);
The problem is that I'd like the splash screen to stay up if the background/next view is still being rendered, as opposed to simply waiting for an arbitrary amount of time. For example, if render time takes 0.2 seconds, and I want the splash page to be up for 2 seconds, I'd like the splash page to close at 2 seconds. If the render time takes 2.8 seconds, I'd like the splash page to stay up for 2.8 seconds. What's the best way to achieve this?
Upvotes: 0
Views: 4539
Reputation: 203
Try "componentDidMount" lifecycle function. react-lifecycle-methods-diagram
Here is the idea:
By the way, if the next screen is not that slow to load, in my opinion it's a little bit over skill.
Upvotes: 1