初始屏幕使用异步操作等待,而字体包使用“自定义挂钩”useFonts
(我猜)。
如何让启动屏幕等待谷歌字体加载?
您可以使用以下方式加载字体loadAsync
from expo-fonts
,并管理启动画面expo-splash-screen
import * as SplashScreen from 'expo-splash-screen';
import * as Font from 'expo-font';
import { Inter_900Black } from '@expo-google-fonts/inter';
export default function App() {
const [appIsReady, setAppIsReady] = useState(false);
useEffect(() => {
(async () => {
try {
await SplashScreen.preventAutoHideAsync();
await Font.loadAsync({ Inter_900Black });
}
catch {
// handle error
}
finally {
setAppIsReady(true);
}
})();
}, []);
const onLayout = useCallback(() => {
if (appIsReady) {
SplashScreen.hideAsync();
}
}, [appIsReady]);
if (!appIsReady) {
return null;
}
return (
<View style={styles.container} onLayout={onLayout}>
<Text style={{fontFamily: 'Inter_900Black'}}>
Example text
</Text>
</View>
);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)