使用本地库时出现错误:You started loading 'Roboto_medium', but used it before it finished loading
。>>
我已按照官方页面上的说明进行操作。
要创建我正在使用create-react-native-app
的React Native应用程序。
App.js
export default class App extends React.Component {
async componentWillMount() {
await Expo.Font.loadAsync({
'Roboto': require('native-base/Fonts/Roboto.ttf'),
'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
'Ionicons': require('@expo/vector-icons/fonts/Ionicons.ttf'),
});
}
render() {
return (
<Container>
<StatusBar hidden={true} />
<Button>
<Text>
Button
</Text>
</Button>
<ListaItens />
</Container>
);
}
}
我收到错误:您开始加载'Roboto_medium',但是在使用本机基础时,在加载完毕之前就使用了它。我已按照官方页面上的说明进行操作。创建本机反应...
您需要等待字体加载完毕。你可以做这样的事情
[如果有人在使用'MaterialIcons'字体系列时遇到此问题,我也遇到类似的问题,并且发现此解决方案有效:
您必须去node_modules / yourPlugin / index.js找到fontFamily并将其删除
此博览会SDK 35的新代码已从@akhil xavier的答案中进行了修改
之所以必须加载字体,是因为您使用的是Native Base Text组件。如果导入React Native Text组件,则您甚至不必加载字体,也不会看到该错误。