所以我得到“Roboto-Black”不是系统字体,尝试通过 Expo.Font.loadAsync() 错误。但我在其他帖子中读到有些人遇到了类似的问题,解决方案是使用等待/承诺。但是,我不确定如何使用我的代码执行此操作,因为我只是按照教程执行此操作,这是我第一次尝试使用具有最少 JS 知识的 create-react-native-app :( 请帮助我检查此代码片段让我知道我做错了什么:
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { Font, AppLoading } from 'expo';
import Router from 'loginDemo/config/routes.js'
import store from 'loginDemo/redux/store.js';
function cacheFonts(fonts) {
return fonts.map(function(font) {return Font.loadAsync(font)});
}
export default class App extends Component {
constructor() {
super();
this.state = {
isReady: false,
}
}
async _loadAssetsAsync() {
const fontAssets = cacheFonts([
{RobotoBlack: require('loginDemo/assets/fonts/Roboto-Black.ttf')},
{RobotoBold: require('loginDemo/assets/fonts/Roboto-Bold.ttf')},
{RobotoMedium: require('loginDemo/assets/fonts/Roboto-Medium.ttf')},
{RobotoRegular: require('loginDemo/assets/fonts/Roboto-Regular.ttf')},
{RobotoLight: require('loginDemo/assets/fonts/Roboto-Light.ttf')}
]);
await Promise.all([...fontAssets]);
}
render() {
if (!this.state.isReady) {
return (
<AppLoading
startAsync={this._loadAssetsAsync}
onFinish={() => this.setState({isReady: true})}
onError={console.warn}
/>
);
}
return (
<Provider store={store}>
<Router/>
</Provider>
);
}
}