【问题标题】:React Native Lottie: Cannot read property 'play' of undefinedReact Native Lottie:无法读取未定义的属性“play”
【发布时间】:2017-05-06 05:00:32
【问题描述】:

我正在使用 Lottie 命令式 API 来显示循环动画。 除了使用 React Native Sound 的组件之外,命令式 API 在我的所有组件上都可以正常工作。我认为问题在于这两个库都是用.play() 调用的。这可能吗?

洛蒂:this.animation.play(); 反应原生声音:this.sound.play()

调用 Lottie 方法后,我收到错误消息:

无法读取未定义的属性“play”

有什么想法吗?

提前致谢。

【问题讨论】:

  • 如果 this.animationthis.sound 未定义,您将收到该错误...
  • 你是对的。 React Native Sound 可以工作,Animation 是通过 Lottie 导入的。

标签: react-native react-native-sound


【解决方案1】:

我终于明白了。 React Native Sound 当然不是问题——它可能只是延迟了 Lottie 的初始化,因此当我调用它时 animation 仍然未定义。

解决方案是内置一个计时器,并且已在此线程中提出建议:https://github.com/airbnb/lottie-react-native/issues/21

  componentDidMount() {
      this.initAnimation();
  }

  initAnimation(){
    if (!this.animation){
      setTimeout(() => {
        this.initAnimation();
      }, 100);
    } else {
        this.animation.play();
    }
  }

【讨论】:

    猜你喜欢
    • 2019-09-27
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    • 1970-01-01
    • 2018-10-22
    • 2018-10-02
    相关资源
    最近更新 更多