From e884d5691e76a4a566f74701bdbf3ef390ffcc5d Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 25 Mar 2026 14:06:27 -0500 Subject: [PATCH] 's' --- app/_layout.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/_layout.tsx b/app/_layout.tsx index 0312479..c81b270 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -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 ; }