我刚刚升级到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;
}
};
谢谢。