Reactjs react native reanimated动画只启用一次
我正在使用reanimated在一个模态中创建一个自定义警报,它可以正常工作,但在该模态可见且内容更新后,动画仅在开始时工作一次,但动画无法工作 这是我的密码Reactjs react native reanimated动画只启用一次,reactjs,react-native,react-native-reanimated,Reactjs,React Native,React Native Reanimated,我正在使用reanimated在一个模态中创建一个自定义警报,它可以正常工作,但在该模态可见且内容更新后,动画仅在开始时工作一次,但动画无法工作 这是我的密码 componentDidUpdate() { // stopClock(clock); if (this.state.visible) { block([ timing(this.val, { toValue: 1, duration: 100,
componentDidUpdate() {
// stopClock(clock);
if (this.state.visible) {
block([
timing(this.val, {
toValue: 1,
duration: 100,
easing: Easing.inOut(Easing.ease),
}).start(),
spring(this.scale, {
toValue: 1,
damping: 12,
mass: 0.6,
stiffness: 150.6,
overshootClamping: false,
restSpeedThreshold: 0.1001,
restDisplacementThreshold: 0.001,
}).start(),
]);
} else {
block([
timing(this.val, {
toValue: 0,
duration: 0,
easing: Easing.inOut(Easing.ease),
}).start(),
spring(this.scale, {
toValue: 0,
damping: 12,
mass: 0.6,
stiffness: 150.6,
overshootClamping: false,
restSpeedThreshold: 0.001,
restDisplacementThreshold: 0.001,
}).start(),
]);
}
}
在运行动画之前,必须将动画值添加为零,如:-
componentDidUpdate() {
// stopClock(clock);
//Setting animations values as zero
this.val.setValue(0);
this.scale.setValue(0);
if (this.state.visible) {
block([
timing(this.val, {
toValue: 1,
duration: 100,
easing: Easing.inOut(Easing.ease),
}).start(),
spring(this.scale, {
toValue: 1,
damping: 12,
mass: 0.6,
stiffness: 150.6,
overshootClamping: false,
restSpeedThreshold: 0.1001,
restDisplacementThreshold: 0.001,
}).start(),
]);
} else {
block([
timing(this.val, {
toValue: 0,
duration: 0,
easing: Easing.inOut(Easing.ease),
}).start(),
spring(this.scale, {
toValue: 0,
damping: 12,
mass: 0.6,
stiffness: 150.6,
overshootClamping: false,
restSpeedThreshold: 0.001,
restDisplacementThreshold: 0.001,
}).start(),
]);
}
}