小编Анд*_*сев的帖子

如何停止反应原生动画

我试图停止反应原生动画,但它不起作用.我试着用stopAnimation方法做到这一点

这是我的代码:

    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(); …
Run Code Online (Sandbox Code Playgroud)

javascript animation reactjs react-native

7
推荐指数
1
解决办法
9144
查看次数

标签 统计

animation ×1

javascript ×1

react-native ×1

reactjs ×1