【发布时间】:2021-05-07 15:06:25
【问题描述】:
(对不起,英语不是第一语言)
我加载了我的字体,但是当我尝试使用它们时,它说字体不是字体,我需要使用 Font.loadAsync
我已经在 APP() 中加载了它们:
import * as Font from "expo-font";
import AppLoading from "expo-app-loading";
import React, { useState } from "react";
import { Actions, Router, Scene } from "react-native-router-flux";
export default function App() {
const fetchFonts = () => {
return Font.loadAsync({
"Montserrat-Bold": require("./assets/fonts/Montserrat-Bold.ttf"),
"Montserrat-Medium": require("./assets/fonts/Montserrat-Medium.ttf"),
"Montserrat-Regular": require("./assets/fonts/Montserrat-Regular.ttf"),
"Montserrat-SemiBold": require("./assets/fonts/Montserrat-SemiBold.ttf"),
"MyriadPro-Regular": require("./assets/fonts/MyriadPro-Regular.otf"),
});
};
const [fontLoaded, setFontLoaded] = useState(false);
if (!fontLoaded) {
return (
<AppLoading
startAsync={fetchFonts}
onFinish={(setFontLoaded(true)}
onError={(console.warn}
autoHideSplash={false}
/>
);
} else {
return (
<Router styles={styles.container}>
...
</Router>
);
}
}
我在另一个屏幕中使用样式中的字体,如下所示:
text: {
textAlign: "center",
padding: 20,
fontFamily: "Montserrat-Bold",
},
错误:
fontFamily "Montserrat-Bold" is not a system font and has not been loaded through Font.loadAsync.
- If you intended to use a system font, make sure you typed the name correctly and that it is supported by your device operating system.
- If this is a custom font, be sure to load it with Font.loadAsync.
at node_modules/expo-font/build/Font.js:27:16 in processFontFamily
at [native code]:null in performSyncWorkOnRoot
at node_modules/react-native/Libraries/ReactNative/renderApplication.js:54:4 in renderApplication
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:117:25 in runnables.appKey.run
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:213:4 in runApplication
at [native code]:null in callFunctionReturnFlushedQueue
【问题讨论】:
-
你能显示错误吗?
-
当然,我把错误放在了问题上
标签: react-native react-hooks expo