reactjs - 自定义 Lottie 动画在 React Native 中不起作用
问题描述
反应原生版本:反应原生:0.59.8
Lottie 版本:“lottie-react-native”:“^3.3.2”
动画正在使用此动画:https ://assets2.lottiefiles.com/datafiles/Hhw0wgYmETDTkxW/data.json
但不是这个(我的自定义):https ://assets9.lottiefiles.com/packages/lf20_NJ8xgn.json
反应本机代码:
import React from 'react';
import { Button, StyleSheet, View } from 'react-native';
import LottieView from "lottie-react-native";
export default class App extends React.Component {
componentDidMount() {
this.animation.play();
// Or set a specific startFrame and endFrame with:
// this.animation.play(30, 120);
}
resetAnimation = () => {
this.animation.reset();
this.animation.play();
};
render() {
return (
<View style={styles.animationContainer}>
<LottieView
ref={animation => {
this.animation = animation;
}}
style={{
width: 400,
height: 400,
backgroundColor: '#eee',
}}
source={require('./assets/gradientBall.json')}
// OR find more Lottie files @ https://lottiefiles.com/featured
// Just click the one you like, place that file in the 'assets' folder to the left, and replace the above 'require' statement
/>
<View style={styles.buttonContainer}>
<Button title="Restart Animation" onPress={this.resetAnimation} />
</View>
</View>
);
}
}
const styles = StyleSheet.create({
animationContainer: {
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
flex: 1,
},
buttonContainer: {
paddingTop: 20,
},
});
解决方案
更改您的乐透版本
安装(React Native == 0.59.x)
安装 lottie-react-native (3.0.2) 和 lottie-ios (3.0.3):
yarn add lottie-react-native@3.0.2
yarn add lottie-ios@3.0.3
或者
npm i --save lottie-react-native@3.0.2
npm i --save lottie-ios@3.0.3
使用 react-native 链接将库添加到您的项目中:
react-native link lottie-ios
react-native link lottie-react-native
在 Expo 的情况下,它适用于 lottie 的第 2 版
推荐阅读
- c++ - 在 C++ 中正确设计 RNG 助手
- javascript - 迭代集合对象MongoDB时如何使用forEach?
- python - 如何将字符串拆分为列表节点?
- ide - PhpStorm 红线下的问题
- java - Spring Boot:以 Json 格式返回匹配顺序
- python - 访问 Internet 时 Pyportal 崩溃
- excel - 使用 InStr 删除列中不包含子字符串的所有行
- android - 使用 dagger 依赖注入更改活动后 Viewmodel 不保留值
- android - 在 Android 上的日历上显示事件
- javascript - 如何在 ReactJS 中一次只删除一项?