Phản ứng gốc giới thiệu API Animated
mới, tôi muốn tạo hoạt ảnh vòng lặp như quy mô bong bóng lên rồi giảm tỷ lệ và lặp lại tiến trình đó.Hoạt ảnh lặp lại với ảnh động mới api
Tuy nhiên tôi không thể tìm ra. Tôi đã thử viết một số mã như bên dưới
class TestProject extends React.Component {
constructor(): void {
super();
this.state = {
bounceValue: new Animated.Value(0),
v: 1,
};
}
componentDidMount() {
this.state.bounceValue.setValue(1.5);
let animation = Animated.timing(this.state.bounceValue, {
toValue: this.state.v,
});
setInterval(() => {
animation.stop();
if (this.state.flag) {
this.state.v = 0.5;
this.state.bounceValue.setValue(0.5);
}
else {
this.state.v = 1.5;
this.state.bounceValue.setValue(1.5);
}
animation.start();
}, 5000);
}
render(): ReactElement {
return (
<View style={styles.imageContainer}>
<Image
style={styles.image}
source={{uri: 'http://image142-c.poco.cn/best_pocoers/20130517/91062013051716553599334223.jpg'}}
/>
<Animated.Text
style={[
styles.test,
{transform: [
{scale: this.state.bounceValue},
],}
]
}>
haha
</Animated.Text>
</View>
);
}
}
nhưng không hoạt động tốt.
Mọi đề xuất sẽ được đánh giá cao.
trước khi lặp, bạn nên kiểm tra xem hoạt ảnh đã hoàn thành hay đã bị hủy, nếu không bạn sẽ không bao giờ có thể dừng nó. Xem câu trả lời của tôi dưới đây: http://stackoverflow.com/questions/31578069/repeat-animation-with-new-animated-api/38393479#38393479 – joshblour
Tìm câu trả lời của silyevsk. Đây là lỗi thời. –
bạn cũng có thể sử dụng this.state.yourAnimation.stopAnimation() khi bạn componentWillUnmount –