Reactjs React Native-Undefined不是对象(正在计算';singleValue.stopTracking';)
我正在尝试通过Reactjs React Native-Undefined不是对象(正在计算';singleValue.stopTracking';),reactjs,react-native,lottie,Reactjs,React Native,Lottie,我正在尝试通过平面列表中的item.id单独播放动画。到目前为止,我能够绑定id并在单击动画时提醒正确的id。不幸的是,动画没有播放,我得到了这个错误Undefined不是一个对象(计算'singleValue.stopTracking') 收集id并应播放为其选定id的动画 我已经检查了其他来源,我仍然不知道为什么会发生这个错误,或者我做错了什么。我想如果我将进度更改为id,可能会触发动画单独播放,但这远远不正确。编辑: 我会尝试这样改变动漫明星: anim_star = (id) =>
平面列表中的item.id
单独播放动画。到目前为止,我能够绑定id并在单击动画时提醒正确的id。不幸的是,动画没有播放,我得到了这个错误Undefined不是一个对象(计算'singleValue.stopTracking')
收集id并应播放为其选定id的动画
我已经检查了其他来源,我仍然不知道为什么会发生这个错误,或者我做错了什么。我想如果我将进度
更改为id,可能会触发动画单独播放,但这远远不正确。编辑:
我会尝试这样改变动漫明星:
anim_star = (id) => {
Alert.alert(id);
let progress = this.state.progress; <---
progress[id] = new Animated.Value(0); <---
this.setState({ progress }); <---
Animated.timing(this.state.progress[id], {
toValue: 1,
duration: 2000,
easing: Easing.linear,
}).start();
}
anim\u star=(id)=>{
警报。警报(id);
让progress=this.state.progress;我尝试了这个,但是错误仍然发生,而且动画不再可见。@VM909您正在尝试设置动画的样式属性是什么?您想要的效果是什么?动画本身正在工作,只是当我单击设置动画时,所有东西都同时设置动画。我只想要一个在anim_star中,尝试将this.setState({progress:new Animated.Value(id)})更改为:this.setState({progress[id]:new Animated.Value(0)})我想我明白了问题所在。现在,您的进度字段是一个Animated.Value。您试图做的是为渲染的每个项目实例化一个离散的Animated.Value。因此,您可能希望将构造函数中的进度字段更改为空对象。这样,当您参考progress[id]
稍后,它指的是在名为progress的状态对象上以给定id命名的字段。
data={ this.state.dataSource}
ItemSeparatorComponent = {this.FlatListItemSeparator}
renderItem={({item}) => <View>
<Card>
<View rkCardFooter>
<TouchableOpacity
onPress={this.anim_star.bind(this, item.id)}
style={{position:'absolute', height: '100%', width: '100%',}}>
<Animation
progress={this.state.progress[item.id]}
source={require('../Animations/favourite_app_icon.json')}
style={{ height: '100%', width: '100%', position: 'absolute'}}
resizeMode="contain"
/>
</TouchableOpacity>
<Text> Sample</Text>
</View>
</Card>
constructor(props)
{
super(props);
this.state = {
isLoading: true,
id: '',
dataSource: '',
progress: new Animated.Value(0),
};
anim_star = (id) => {
Alert.alert(id);
let progress = this.state.progress; <---
progress[id] = new Animated.Value(0); <---
this.setState({ progress }); <---
Animated.timing(this.state.progress[id], {
toValue: 1,
duration: 2000,
easing: Easing.linear,
}).start();
}
constructor(props)
{
super(props);
this.state = {
isLoading: true,
id: '',
dataSource: '',
progress: {}, <---
};
render() {
return(
<Animated.Image
style={{ height: '100%', width: '100%', position: 'absolute', opacity: this.state.progress}}
source={require('../Animations/favourite_app_icon.json')}
resizeMode={`contain`}
/>
)
}