如何停止反应原生动画

时间:2017-05-17 11:00:27

标签: javascript reactjs animation react-native

我试图在本机中停止动画,但它不起作用。     我尝试使用stopAnimation method

执行此操作

这是我的代码:

    constructor(props) {
        super(props);
        //...
        this.state = {
            posY: new Animated.Value(0),
            posX: new Animated.Value(0),
            //...
        };
    }

    componentWillMount(){
        //...
        let eventEmitter = getGlobalEventEmitter();

        eventEmitter.emit('initialize', {words : true});
        eventEmitter.addListener('startGame', ()=>{
            this.setState({initialized: true});
            this.updateText();
        });
    }

    updateText(){

        let currentText = [];
        //... set some values to currentText

        this.props.setText(currentText); // store in redux
        this.startText(this.effects[textEffect]['duration']);
    }

    startText(duration) {

        let viewHeight = 530;
        let fallTo = 500;


        Animated.timing(
            this.state.posY,
            {
                toValue: fallTo,
                duration: duration
            }
        ).start();


        let stopAnimation = function(){
            this.state.posY.stopAnimation();
            console.log("ANIMATION SHOULD STOP");
        };
        stopAnimation = stopAnimation.bind(this);

        eventEmitter.addListener('wordGuessed', ()=>{            
            stopAnimation();
        });

    }

在另一个组件中,我正在触发wordGuessed事件,并且控制台日志有效。我做错了什么?

1 个答案:

答案 0 :(得分:20)

致电

SELECT
    t1.FirstName, count(*)
FROM
    RequestsTable t1
WHERE t1.status = 'played'
GROUP BY t1.FirstName;