animation = new Animated.Value(0);
animationSequnce = Animated.sequence(
[Animated.timing(this.animation, { toValue: 1 }),
Animated.timing(this.animation, { toValue: 0, delay: 1000 }),
],
);
startAnimation = () => {
animationSequnce.start();
}
stopAnimation = () => {
animationSequnce.stop();
}
Я хочу запустить animation sequence
несколько раз.
Я проверил это, написав код, который вызывает startAnimation
при нажатии кнопки. Анимация запускается при первом запуске. При нажатии второй кнопки после завершения первой анимации возникает ошибка Cannot read property 'start' of undefined
.
startAnimation = () => {
Animated.sequence(
[Animated.timing(this.animation, { toValue: 1 }),
Animated.timing(this.animation, { toValue: 0, delay: 1000 }),
],
).start();
}
Это изменение на startAnimation
не вызовет ошибки, но вы не сможете вызвать stopAnimation
, потому что каждый раз будет вызываться другой AnimationSequnce
.
Как лучше всего использовать анимацию несколько раз?