我正在尝试在我的RN应用中使用Lottie。我按照文档操作,下载了JSON文件,在RN中创建了一个文件夹来存储该JSON,但该文件夹不起作用。我还在ios文件夹中进行了“ pod安装”。该应用程序没有中断,我只在屏幕和标题上看到白色图像。有人知道怎么可能出问题了吗?我还没有接触过Podfile,所以我想知道是否可能?
这是心脏动画的文件夹。
//HeartAnimation.js
import React, { Component } from "react";
import { View, StyleSheet } from "react-native";
import LottieView from "lottie-react-native";
import task from "./task.json";
class HeartAnimation extends React.Component {
static navigationOptions = {
title: "The Simpsons",
headerStyle: {
backgroundColor: "#53b4e6"
},
headerTintColor: "#f6c945",
headerTitleStyle: {
fontWeight: "bold"
}
};
constructor(props) {
super(props);
this.state = {};
}
render() {
return (
<View style={styles.container}>
<LottieView
style={{ width: 400, height: 400 }}
source={'./task.json'}
autoPlay
loop
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "white"
}
});
export default HeartAnimation;
答案 0 :(得分:0)
<LottieView
style={{ width: 400, height: 400 }}
source={require('./task.json')}
autoPlay
loop
/>
源应该具有这样的语法 source = {require('./ task.json')}