【发布时间】:2022-07-29 01:50:45
【问题描述】:
我刚刚升级到 Expo SDK 45,我收到一条警告:“不推荐使用 expo-app-loading 来支持 expo-splash-screen:请改用 SplashScreen.preventAutoHideAsync() 和 SplashScren.hideAsync()。https://docs.expo.dev/versions/latest/sdk/splash-screen/ . 所以我做了并按照提供的链接进行操作。
我现在遇到的问题是,在示例中,他们在根视图的 onLayOut 上调用了 onLayOutRootView。现在我正在使用 react-navigation,因此我的根视图嵌套在我的应用程序中。
我是否必须将此函数传递给根视图,或者有没有办法将此函数传递给我的提供者/导航容器之一?还是有其他修复方法?
//imports
export default App = () => {
const [appIsReady, setAppIsReady] = useState(false);
const scheme = "dark";
useEffect(() => {
async function prepare() {
try {
// Keep the splash screen visible while we fetch resources
await SplashScreen.preventAutoHideAsync();
// Pre-load fonts, make any API calls you need to do here
await Font.loadAsync(customFonts);
} catch (e) {
console.warn(e);
} finally {
// Tell the application to render
setAppIsReady(true);
}
}
prepare();
}, []);
const onLayoutRootView = useCallback(async () => {
if (appIsReady) {
await SplashScreen.hideAsync();
}
}, [appIsReady]);
if (appIsReady) {
return (
<StripeProvider publishableKey={PUBLISHABLE_KEY}>
<ThemeProvider theme={scheme === "dark" ? darkTheme : lightTheme}>
<StatusBar barStyle={scheme === "dark" ? "light-content" : "dark-content"} />
<OrderProvider>
<CartProvider>
<FavoriteProvider>
<FirebaseProvider>
<UserProvider>
<NavigationContainer
theme={scheme === "dark" ? darkTheme : lightTheme}
ref={navigationRef}
>
<RootStackScreens on/>
</NavigationContainer>
</UserProvider>
</FirebaseProvider>
</FavoriteProvider>
</CartProvider>
</OrderProvider>
</ThemeProvider>
</StripeProvider>
);
} else {
return null;
}
};
谢谢。
【问题讨论】:
-
Hey Bert - 遇到同样的问题,哈哈,刚刚进入 45 世博会。我刚刚放弃了整个回调。我得到“SplashScreen.show 已经被调用”,只是将真正的回报隐藏在 if isReady 后面。 - 我希望其他人有更好的贡献哈哈
-
标记的答案对我有用 :)
标签: react-native expo react-navigation