tanpuer
tanpuer

Reputation: 59

Can animation in react native be paused and restarted?

onAnimation(){

    var animation = Animated.timing(this.state.spin,{
        toValue:1,
        duration:4000,
        easing:Easing.linear
    });
    animation.start();
}


onPause(){
    this.state.spin.stopAnimation();
}

I am practicing animations in react native. As code shown above, the animation's velocity will becoming slower because 'the.state.spin' has changed but the animation time is still 4000ms.So I want to reset the state.But the 'the.state.spin' is a Animated.Value. I don't know how to restart the animation without slowing the animation velocity.

Can anyone help me or tell me the correct way to pause and restart the animation?

Upvotes: 2

Views: 7903

Answers (1)

Swordsman
Swordsman

Reputation: 1947

According to Official Doc here

you can pass a callback to stopAnimation like:

this.state.spin.stopAnimation(this.callback);

then you can get the final value after stopping the animation in the callback. You can do whatever you want with the value, like adjust the duration to achieve the restart function.

Upvotes: 7

Related Questions