This commit is contained in:
eric
2026-03-25 14:06:27 -05:00
parent e1a7b1d2d7
commit e884d5691e

View File

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