React Native引入动画效果

版权声明:如要转发,请注明出处,小小喵的微博 https://blog.csdn.net/weixin_42881744/article/details/82744893

此处运用了Lottie动画,请参考https://www.lottiefiles.com/

首先安装 npm i lottie-web
页面中引入

import lottie from 'lottie-web'
import animationData  from './data.json'; //这里引入你的动画json文件

代码中写入

componentDidMount() {
    lottie.loadAnimation({
        container: document.querySelector("#lottie"), // the dom element that will contain the animation
        renderer: 'svg',
        loop: true,
        autoplay: true,
        animationData: animationData// the path to the animation json
    });
}
render(){
    return(
     <View  id="lottie"></View>
    )
}

然后运行页面就能看到动画效果了

猜你喜欢

转载自blog.csdn.net/weixin_42881744/article/details/82744893