在React Native中停止顺序动画

时间:2016-08-01 17:40:15

标签: javascript reactjs react-native

我有按钮A启动的顺序动画,如何通过按钮B停止动画?谢谢

1 个答案:

答案 0 :(得分:1)

将动画存储在状态变量中,并在点击按钮时调用startstop

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()} />
}

有关startstop的更多信息,请参阅https://facebook.github.io/react-native/docs/animations.html