Open jasonleewimi opened 3 years ago
Hello. Please type this in the command pannel:
expo install expo-app-loading
Also, do not destructure AppLoading while importing. Use:
import AppLoading from 'expo-app-loading';
Finally, do not forget onError prompt of AppLoading. Use it like this:
<AppLoading startAsync = {getFonts} onFinish = {() => setFontsLoaded(true)} onError={() => console.log('error')} />
use this code in your App.js file instead after pasting your custom fonts in your assets/fonts folder.
import { useCallback } from 'react'; import { useFonts } from 'expo-font'; import * as SplashScreen from 'expo-splash-screen'; import Home from './screens/home'; import {View} from 'react-native';
SplashScreen.preventAutoHideAsync();
export default function App() { const [fontsLoaded, fontError] = useFonts({ 'Nunito-Bold': require('./assets/fonts/Nunito-Bold.ttf'), 'Nunito-Regular': require('./assets/fonts/Nunito-Regular.ttf'),
});
const onLayoutRootView = useCallback(async () => { if (fontsLoaded || fontError) { await SplashScreen.hideAsync(); } }, [fontsLoaded, fontError]);
if (!fontsLoaded && !fontError) { return null; } return (
); }
`import React, {useState} from 'react'; import * as Font from 'expo-font'; import Home from './screens/home'; import {AppLoading} from 'expo-app-loading';
const getFonts = () => { return Font.loadAsync({ 'nunito-regular': require('./assets/fonts/Nunito-Regular.ttf'), 'nunito-bold': require('./assets/fonts/Nunito-Bold.ttf') }); }
export default function App() { const [fontsLoaded, setFontsLoaded] = useState(false);
if(fontsLoaded){ return (
}else { return( <AppLoading startAsync = {getFonts} onFinish = {() => setFontsLoaded(true)} /> ); } }`