lottie-react-native动画无法播放的解决方法

当前使用的版本号:
 "lottie-ios": "^3.1.8",
 "lottie-react-native": "^3.5.0"
 
遇到的情况:
1.动画在手机上无法播放,官网上可以播放;
2.动画资源切换之后,动画无法执行; 
3.android、iOS平台差异,在android可以播放,iOS平台无法播放;
4.三星某手机,动画无法播放;(之前一直动画可以执行,某天突然无法执行了,手机恢复出厂设置又好了..)


针对以上四种情况:
 使用方法:

<LottieView
	ref={animation => {this.animation = animation}}
	style={styles.lottieStyle}
	source={require('./animation/lottie.json')}
	loop={true}
	autoPlay={true}
	enableMergePathsAndroidForKitKatAndAbove/>
	// 将动画重置
    this.animation && this.animation.reset();
	
	// TODO 切换动画资源
	// do something
	
	this.setTimer && clearTimeout(this.setTimer);
	// 主要针对情况3,iOS平台切换资源之后,无法播放的问题,无此情况可不延迟
	this.setTimer = setTimeout(()=>{
		this.animation && this.animation.play();  // 开始播放动画
	},5);

以上即为本人使用lottie遇到的一些情况,希望有所帮助,记得点赞三连~

猜你喜欢

转载自blog.csdn.net/qq_33539839/article/details/114832657
今日推荐