's'
This commit is contained in:
@@ -20,26 +20,34 @@ export const unstable_settings = {
|
|||||||
// Prevent the splash screen from auto-hiding before asset loading is complete.
|
// Prevent the splash screen from auto-hiding before asset loading is complete.
|
||||||
SplashScreen.preventAutoHideAsync();
|
SplashScreen.preventAutoHideAsync();
|
||||||
|
|
||||||
|
/** 避免部分真机/构建环境下字体加载挂起或失败时永远停在 Expo 默认靶心启动图 */
|
||||||
|
const SPLASH_FALLBACK_MS = 4000;
|
||||||
|
|
||||||
export default function RootLayout() {
|
export default function RootLayout() {
|
||||||
const [loaded, error] = useFonts({
|
const [loaded, error] = useFonts({
|
||||||
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
|
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Expo Router uses Error Boundaries to catch errors in the navigation tree.
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (error) throw error;
|
if (error) {
|
||||||
|
console.warn('[expo-font]', error);
|
||||||
|
}
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
SplashScreen.hideAsync();
|
void SplashScreen.hideAsync();
|
||||||
}
|
}
|
||||||
}, [loaded]);
|
}, [loaded]);
|
||||||
|
|
||||||
if (!loaded) {
|
useEffect(() => {
|
||||||
return null;
|
const t = setTimeout(() => {
|
||||||
}
|
void SplashScreen.hideAsync();
|
||||||
|
}, SPLASH_FALLBACK_MS);
|
||||||
|
return () => clearTimeout(t);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 不再在字体未就绪时 return null,否则 hideAsync 后会出现纯白屏且仍无界面
|
||||||
return <RootLayoutNav />;
|
return <RootLayoutNav />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user