我刚刚开始学习React-Native的Animatable库,并且无法弄清楚如何从函数中启动动画。
例如,我有:
<Animatable.View animation={custom1}>
<View style={styles.itemOne}>
<Text>Hello World</Text>
</View>
</Animatable.View>
和
const custom1 = {
0: {
scale: 15,
},
1: {
scale: 1,
}
}
自然地,当页面加载时,我的“ custom1”动画立即在视图上执行。
但是,如果我不希望在“调用”“ custom1”动画之前(而不是在页面加载时)执行动画,该怎么办?例如,如果我想这样做:
function initiateCustom1() {
custom1.animate()
}
我将如何完成?
我以为您正在使用此库?
如果是,则可以使用ref
道具。
<Animatable.View
animation='zoomInUp'
ref={ref => {
this.sample = ref;
}}
>
<Text>Sample</Text>
</Animatable.View>
并在您的可触摸或按钮上
onPress={() => {
this.sample.zoomOutDown();
// or
this.sample.zoomOutDown().then(() => {
// do something after animation ends
});
}}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句