gpt4 book ai didi

javascript - 如何停止 react native 动画

转载 作者:数据小太阳 更新时间:2023-10-29 04:54:33 27 4
gpt4 key购买 nike

我试图在 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 事件,并且控制台日志有效。我做错了什么?

最佳答案

打电话

Animated.timing(
this.state.posY
).stop();

关于javascript - 如何停止 react native 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44022964/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com