【问题标题】:React Native (Expo) says font has not been loaded with Font.loadAsync (but I think it has)React Native (Expo) 说字体没有加载 Font.loadAsync (但我认为它有)
【发布时间】:2020-07-19 20:01:57
【问题描述】:

这是我的代码的 sn-p:

export default class HomeScreen extends React.Component {
  state = {
    fontLoaded: false,
  };

  async componentDidMount() {
    await Font.loadAsync({
      'Ubuntu-Regular': require('../assets/fonts/Ubuntu-Regular.ttf'),
      'Ubuntu-Bold': require('../assets/fonts/Ubuntu-Bold.ttf'),
    });

    this.setState({ fontLoaded: true });
  }

  render() {
  ...

但我仍然收到错误消息“fontFamily "ubuntu-bold" 不是系统字体,尚未通过 Font.loadAsync 加载。”

可能是什么问题?我真的被这个难住了。我刚刚升级到 Expo SDK 37.0.0,但是在执行此操作之前我遇到了类似的问题,所以我不确定是不是这个问题。

它也不会在 Ubuntu Regular 中加载,但它是 Ubuntu-Bold 在 Expo 上首先闪烁并出现错误。

【问题讨论】:

  • 您的大小写正确吗?在你的问题中你说“ubuntu-bold”没有加载,你的代码说“Ubuntu-Bold”
  • 是的,两种方式我都试过了,无论哪种方式我仍然得到错误,它反映了我是否已经大写。

标签: react-native expo custom-font system-font


【解决方案1】:

watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && rm -f package-lock.json && rm -f yarn.lock && npm cache verify && npm install && expo r -c

试试这个

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2022-06-17
  • 2021-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-19
  • 1970-01-01
  • 2021-06-27
相关资源
最近更新 更多