【问题标题】:react native parsing Lottie file into state?将本机解析 Lottie 文件反应成状态?
【发布时间】:2018-10-15 03:10:44
【问题描述】:

我正在尝试在我的应用中实现 Lottie 动画,我正在使用 expo SDK, 所以我遵循了世博会的文档,

_loadAnimationAsync = async () => {
let result = await fetch(
  'https://cdn.rawgit.com/airbnb/lottie-react-native/635163550b9689529bfffb77e489e4174516f1c0/example/animations/Watermelon.json'
);

this.setState(
  { animation: JSON.parse(result._bodyText) },
  this._playAnimation
);

};

我收到 [未处理的承诺拒绝:语法错误:JSON 解析错误:意外的标识符“未定义”]。

结果 ._bodyText 是空的还是未定义的??

【问题讨论】:

    标签: animation react-native jsx lottie


    【解决方案1】:

    我刚刚遇到同样的问题并修复了。

    修改 _loadAnimationAsync 应该可以正常工作。

    _loadAnimationAsync = async () => {
    let result = await fetch(
      'https://cdn.rawgit.com/airbnb/lottie-react-native/635163550b9689529bfffb77e489e4174516f1c0/example/animations/Watermelon.json'
    )
      .then(data => {
        return data.json();
      })
      .catch(error => {
        console.error(error);
      });
    this.setState({ animation: result }, this._playAnimation);
    };
    

    如果您有兴趣,我也为此问题发起公关。 here

    【讨论】:

      猜你喜欢
      • 2020-05-08
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 2017-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      相关资源
      最近更新 更多