我将使用React Native Lottie Wrapper来显示屏幕上的动画。我需要一种功能来播放/暂停/恢复动画。
这是我的部分代码:
动画播放得很好,但我无法暂停和恢复它。 有人有解决这个问题的方法吗?
附言:我尝试在pauseLottie()方法中使用this.animation,但它说未定义。
提前感谢!
这是我的部分代码:
...
constructor(props) {
super(props);
this.state = {
progress: new Animated.Value(0)
};
}
static navigationOptions = {
title: "Details",
headerStyle: {
backgroundColor: '#f4511e',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTruncatedBackTitle: 'List'
};
componentDidMount() {
this.animation.play();
}
playLottie() {
console.log('play');
}
pauseLottie() {
console.log('pause');
}
render() {
return (
<View>
<Animation
ref={animation => { this.animation = animation; }}
source={require('../../../../assets/anim/balloons.json')}
style={{height: 300, width: '100%'}}
loop={false}
progress={this.state.progress}
/>
<Text>Course with id: {this.props.navigation.state.params.courseId}</Text>
<Button
onPress={this.playLottie}
title="Play Lottie"
color="#841584"
accessibilityLabel="Play video"
/>
<Button
onPress={this.pauseLottie}
title="Pause Lottie"
color="#841584"
accessibilityLabel="Pause video"
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
...
动画播放得很好,但我无法暂停和恢复它。 有人有解决这个问题的方法吗?
附言:我尝试在pauseLottie()方法中使用this.animation,但它说未定义。
提前感谢!