Gerard Taub
Gerard Taub

Reputation: 177

stop sequenced animation in React Native

I have a sequenced animation started by button A, how can I stop the animation by button B?thank you

Upvotes: 0

Views: 2323

Answers (1)

FuzzyTree
FuzzyTree

Reputation: 32392

Store your animation in a state variable and call start or stop when you click a button:

constructor() {
    super(props);

    var my_animation = ... // define your animation here

    this.state = {
        my_animation: my_animation;
    }
}

startAnimation() {
    this.state.my_animation.start();
}

stopAnimation() {
    this.state.my_animation.stop();
}

render() {
    <Button onPress={() => this.startAnimation()} />
    <Button onPress={() => this.stopAnimation()} />
}

For more info on start and stop see https://facebook.github.io/react-native/docs/animations.html

Upvotes: 1

Related Questions