fontFamily "Open-sans" 不是系统字体,还没有通过 Font.loadAsync 加载。
如果您打算使用系统字体,请确保您输入的名称正确并且您的设备操作系统支持该名称。
如果这是自定义字体,请务必使用 Font.loadAsync 加载它。
node_modules\react-native\Libraries\LogBox\LogBox.js:148:8 in registerError
node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl
node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error
node_modules\expo\build\environment\react-native-logs.fx.js:27:4 错误
node_modules\expo\node_modules\expo-font\build\Font.js:29:16 in processFontFamily
import AppLoading from 'expo-app-loading';
import * as Font from 'expo-font';
const fetchFonts = () => {
return Font.loadAsync({
'Open-sans': require('./assets/fonts/OpenSans-Regular.ttf'),
'Open-sans-bold': require('./assets/fonts/OpenSans-Bold.ttf')
});
};
export default function App() {
const [fontLoaded, setfontLoaded] = useState(false);
if (!fontLoaded) {
return (
<AppLoading
startAsync={fetchFonts}
onFinish={() => {
setfontLoaded(true);
}}
onError={console.warn}
/>
);
}
我的 package.json
"dependencies": {
"expo": "~40.0.0",
"expo-app-loading": "^1.0.1",
"expo-font": "^8.4.0",
"expo-status-bar": "~1.0.3",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",
"react-native-gesture-handler": "~1.8.0",
"react-native-reanimated": "~1.13.0",
"react-native-web": "~0.13.12",
"react-navigation": "^4.4.3",
"react-navigation-drawer": "^2.6.0",
"react-navigation-header-buttons": "^6.2.1",
"react-navigation-stack": "^2.10.2",
"react-navigation-tabs": "^2.10.1",
"react-redux": "^7.2.2",
"redux": "^4.0.5"