I have a simple loop animation in my component:
runAnimation() { console.log('run animation'); this.state.angle.setValue(0); Animated.timing(this.state.angle, { toValue: 360, duration: 8000, easing: Easing.linear }).start(() => this.runAnimation()); } ... <Animated.Image style={[ styles.rotate, { transform: [ { rotate: this.state.angle.interpolate({ inputRange: [0, 360], outputRange: ['0deg', '360deg'] })}, ]} ]} source={require('./spinning_ball.png')} />
How to stop this animation? For example, when switching to another screen or after a user presses a button.
I tried using this.state.angle.stopAnimation () , but noticed that the run animation is still being saved in the console. Is there any other stop method that I have to call to prevent the callback from starting?
source share