正在加载基于字体的本地错误

问题描述 投票:23回答:5

使用本地库时出现错误:You started loading 'Roboto_medium', but used it before it finished loading。>>

enter image description here

我已按照官方页面上的说明进行操作。

要创建我正在使用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',但是在使用本机基础时,在加载完毕之前就使用了它。我已按照官方页面上的说明进行操作。创建本机反应...

reactjs react-native native-base
5个回答
49
投票

您需要等待字体加载完毕。你可以做这样的事情


2
投票

[如果有人在使用'MaterialIcons'字体系列时遇到此问题,我也遇到类似的问题,并且发现此解决方案有效:


0
投票

您必须去node_modules / yourPlugin / index.js找到fontFamily并将其删除


0
投票

此博览会SDK 35的新代码已从@akhil xavier的答案中进行了修改


-2
投票

之所以必须加载字体,是因为您使用的是Native Base Text组件。如果导入React Native Text组件,则您甚至不必加载字体,也不会看到该错误。

© www.soinside.com 2019 - 2024. All rights reserved.