【发布时间】:2020-02-28 19:04:51
【问题描述】:
在初始化模板“tabs”Expo 项目后,React Native 应用程序的启动例程如下所示:
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关于让“启动画面停留更长时间”的简单演示:
import { SplashScreen } from 'expo';
SplashScreen.preventAutoHide();
setTimeout(SplashScreen.hide, 5000);
问题是,如果仍在呈现背景/下一个视图,我希望启动画面保持不变,而不是简单地等待任意时间。例如,如果渲染时间需要 0.2 秒,并且我希望启动页面持续 2 秒,我希望启动页面在 2 秒时关闭。如果渲染时间需要 2.8 秒,我希望启动页面保持 2.8 秒。实现这一目标的最佳方法是什么?
【问题讨论】:
标签: javascript react-native mobile expo splash-screen