Expo React Native安卓端字体加载失败,Web端正常问题求助
Expo React Native安卓端自定义字体加载失败问题
- 开发背景:跟随React Native 2023入门教程开发,当前进度到40分58秒
- 问题现象:Web端字体显示正常,但安卓端所有自定义字体均加载失败,报错信息如下:
fontFamily "DMRegular" is not a system font and has not been loaded through Font.loadAsync. 1. 若您使用系统字体,请确保名称输入正确且设备系统支持该字体。 2. 若为自定义字体,请务必通过Font.loadAsync加载。 - 已尝试无效的解决方案:
- 添加
react-native.config.js配置文件 - 改用旧版
Font.loadAsync方法加载字体 - 移除样式表中的
fontWeight属性 - 删除并重新安装
node_modules
- 添加
Layout组件代码:
import { Stack } from "expo-router"; import { useCallback } from "react"; import { useFonts } from "expo-font"; import * as SplashScreen from 'expo-splash-screen' SplashScreen.preventAutoHideAsync() const Layout = () => { const [fontsLoaded] = useFonts({ DMBold: require('../assets/fonts/DMSans-Bold.ttf'), DMMedium: require('../assets/fonts/DMSans-Medium.ttf'), DMRegular: require('../assets/fonts/DMSans-Regular.ttf'), }) const onLayoutRootView = useCallback(async () => { if(fontsLoaded) { await SplashScreen.hideAsync() } }, [fontsLoaded]) if(!fontsLoaded) { return null } return <Stack onLayout={onLayoutRootView} /> } export default Layout
内容的提问来源于stack exchange,提问作者Ammar Abbara
相关产品推荐
相关产品推荐

