当尝试使用Apploading插入Expo中的自定义字体时,我会获得语法错误,“这些文件都不存在”。
我正在尝试将自定义字体插入React Native Expo中。我正在使用Apploading方法。由于某种原因,我收到一条错误消息,说“这些文件都不存在”
我的博览会版本是5.4.0。我已经寻找类似的问题,但是它们要么不涉及字体,要么使用字体异步而不是应用程序加载。
这是我下面的完整代码。
import 'react-native-gesture-handler';
import React from 'react';
import { createStackNavigator } from '@react-navigation/stack';
import { NavigationContainer } from '@react-navigation/native';
import HomeScreen from './src/screens/HomeScreen';
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import AppLoading from 'expo-app-loading';
import { useFonts } from 'expo-font';
import { Font } from 'expo';
const Stack = createStackNavigator();
export default function App() {
let [fontsLoaded] = useFonts({
'SEGOEUI': require('./assets/fonts/SEGOEUI.TTF'),
});
if (!fontsLoaded) {
return <AppLoading />;
}
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home" screenOptions={{ headerShown: false }}>
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
I am trying to insert a custom font into React Native Expo. I am using the AppLoading method. For some reason, I get an error message saying "None of these files exist"
...even though the file clearly does exist in the file directory:
My Expo version is 5.4.0. I've looked for similar questions, but they either don't involve fonts, or they are using font Async rather than AppLoading.
This is my full code below.
import 'react-native-gesture-handler';
import React from 'react';
import { createStackNavigator } from '@react-navigation/stack';
import { NavigationContainer } from '@react-navigation/native';
import HomeScreen from './src/screens/HomeScreen';
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import AppLoading from 'expo-app-loading';
import { useFonts } from 'expo-font';
import { Font } from 'expo';
const Stack = createStackNavigator();
export default function App() {
let [fontsLoaded] = useFonts({
'SEGOEUI': require('./assets/fonts/SEGOEUI.TTF'),
});
if (!fontsLoaded) {
return <AppLoading />;
}
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home" screenOptions={{ headerShown: false }}>
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加要加载到
Metro.config.js
文件的字体文件的文件扩展名类型应该看起来像这样:
try adding the file extension type of the font file you are trying to load to the
metro.config.js
fileshould look something like this: