I have been building a react native expo app from the latest version.
Everything was working fine until I got farther into the project.
It seems to be getting suck loading the Font. It will load it 25% of the time. I have tried serval different ways to use a callback make an await for the font but nothing seems to work.
I have reverted the code back to the boilerplate. And again. I will work 25% of the time.
for 20 minutes it will not load the font and go to the:
<Stack.Screen name=”+not-found” />
ill get frustrated trying to fix it and then boom it loads again no problem to the:
<Stack.Screen name=”(tabs)” options={{ headerShown: false }} />
Stack
here is the code:
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
import { useFonts } from 'expo-font';
import { Stack } from 'expo-router';
import * as SplashScreen from 'expo-splash-screen';
import { useEffect, useCallback } from 'react';
import 'react-native-reanimated';
import { useColorScheme } from '@/hooks/useColorScheme';
SplashScreen.preventAutoHideAsync();
export default function RootLayout() {
const colorScheme = useColorScheme();
const [loaded] = useFonts({
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
});
useEffect(() => {
if (loaded) {
SplashScreen.hideAsync();
}
}, [loaded]);
if (!loaded) {
return null;
}
return (
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="+not-found" />
</Stack>
</ThemeProvider>
);
}
another note, as I make changes in another file it will crashout to the “+not-found” stack
but all I have to do sometimes is change a letter in a single component and it will work again.
from:
<Text>This is a test</Text>
to:
<Text>This is a testtttttt</Text>
and boom the whole app will load again.
any help would be greatly apperciated and if you need any more information let me know.
but again i change no config whats so ever, just add those “tttt”‘s and its back. Sometimes.
Mitch Dupuie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.