我试图在 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/