我的应用程序使用 CRNA 和 Expo,我的问题是 Font.loadAsync() 异步函数无法在我的项目目录的 assets/fonts/ 文件夹中找到 .otf 字体文件。我绝对确定目录和文件名是正确的。我收到此错误。
这是我的代码:
import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Font, AppLoading } from 'expo'
import Root from './js/Root';
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
fontLoaded: false
}
}
async componentDidMount() {
await Font.loadAsync({
"Light": require('./assets/fonts/SemplicitaPro-Light.otf')
})
this.setState({ fontLoaded: true })
}
render() {
if (!this.state.fontLoaded) {
return <AppLoading />
}
return <Root />; …Run Code Online (Sandbox Code Playgroud)