【发布时间】:2021-08-12 02:18:43
【问题描述】:
我正在尝试通过item.id 在flatlist 中单独播放动画。到目前为止,我能够绑定 id 并在单击动画时提醒正确的。不幸的是,动画无法播放,我收到此错误Undefined is not an object (evaluating 'singleValue.stopTracking')。
anim_star = (id) => {
Alert.alert(id);
this.setState({ progress: new Animated.Value(id) });
Animated.timing(this.state.progress[id], {
toValue: 1,
duration: 2000,
easing: Easing.linear,
}).start();
}
收集 id 并应播放选择了任何 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),
};
我检查了其他来源,但我仍然不知道为什么会发生此错误或我做错了什么。我想也许如果我将 progress 更改为 id,那么这将触发动画单独播放,但这远非正确。
【问题讨论】:
标签: reactjs react-native lottie