我尝试为我的 expo ios 应用程序上传自定义字体,但总是有一些讨厌的错误不会消失,并且 google/github/stackoverflow 的修复也没有帮助。 最后错误总是
这是我的情况
我的字体位于/assets/fonts/Avenir LT 95 Black Oblique.ttf
我把插件写在app.json文件中
[
"expo-font",
{
"fonts": ["./assets/fonts/Avenir LT 95 Black Oblique.ttf"]
}
]
我有一个react-native-config.js,里面有这个
module.exports = {
project: {
ios: {},
android: {},
},
assets: ["./assets/fonts"],
};
在我的 app.js 中,我尝试运行以下几行:
import { useCallback } from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { useFonts } from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
SplashScreen.preventAutoHideAsync();
export default function App() {
const [fontsLoaded, fontError] = useFonts({
'Inter-Black': require('./assets/fonts/Inter-Black.otf'),
});
const onLayoutRootView = useCallback(async () => {
if (fontsLoaded || fontError) {
await SplashScreen.hideAsync();
}
}, [fontsLoaded, fontError]);
if (!fontsLoaded && !fontError) {
return null;
}
我已经尝试过此修复,但AppLoading已被弃用,所以ofc它并没有真正起作用
我已经尝试了“zdivozzo”的提示它使错误进入警告并说
再次,该字体被写为 app.json 中的插件,我已经检查了拼写一百万次,看起来不错。
我在这里缺少什么?有人可以帮助我吗?
我的节点是最新的,我什至尝试删除node_modules并重新安装它,但没有任何改变
我相信您使用的是 macOS。 MacOS 系统中并未安装所有字体。此错误可能不是由您的代码引起的。如果您使用的是 macOS,则还需要在系统中安装该字体系列,只需从查找器中打开 ttf 文件,如果尚未安装,它将提供安装该字体的选项。希望这有帮助。