最近在想通过Lottie往RN加点动画效果。网上有一堆导入json的教程,最开始体验良好。等做到控制模块时发现,控制播放暂停功能中,网上大多数采用reset的方法直接将动画重置,不符合需求,在米家环境中直接使用pause/resume无反应(有方法实现的话欢迎指出),在翻阅Lottie文档api发现有这么一个属性,打算另辟蹊径。
Prop | Description | Default |
---|---|---|
speed | The speed the animation will progress. Sending a negative value will reverse the animation | 1 |
<LottieView
speed={this.state.speed}
ref={this.setAnim}
autoPlay={!progress}
style={ { width: 350, height: 200 }}
source={example.getJson()}
progress={progress}
loop={loop}
enableMergePathsAndroidForKitKatAndAbove
/>
在LottieView中设置speed属性,默认1,在需要控制暂停的时候,通过setState的方法将speed设为0,若要恢复播放状态则将speed设为1即可。