gpt4 book ai didi

react-native - react native : Animation not working properly on android

转载 作者:行者123 更新时间:2023-12-04 16:36:01 24 4
gpt4 key购买 nike

过去 2 天我一直在尝试解决问题,它在 iOS 上运行良好

constructor(){
super();

this.animation = new Animated.Value(0)

this.state = {
expanded: false,
};
}
toggle(){
let initialValue = this.state.expanded? 1 : 0 ,
finalValue = this.state.expanded? 0 : 1

this.setState({
expanded: !this.state.expanded,
});

this.animation.setValue(initialValue)
Animated.timing(
this.animation,
{
toValue: finalValue,
}
).start();
}

render(){
return(
<Animated.View style={{{flex: 1, marginTop: 28, paddingLeft: 25, transform: [{ scale: this.animation }, {perspective: 1000 }]}}}>
....
</Animated.View>

);
}

该组件是 child ,在 parent 中使用如下: <FeedBack ref={ref => this.feedback = ref}/>没有任何条件来检查是否显示(因为动画比例在构造函数中设置为零,所以不需要)
toggle()按下按钮时从父级调用方法。

现在 this works fine on iOS ,当组件加载时, View 不存在,直到按下按钮(然后缩放)。但在 android当组件加载时, View 已经存在。当我按下按钮时,动画 View 消失并重新出现(带有动画缩放),随后的切换工作正常。 android 中的问题是即使 initialValue比例为零, View 在第一次加载时仍然存在。

最佳答案

这是 react-native 的问题在 android 方面有一段时间了(叹气)。似乎将值设置为 0去掉它的特征,基本上认为它是null然后在动画为 > 0 后恢复使用其实际值

解决方法是像这样设置动画
this.animation = new Animated.Value(0.01);
您可以关注问题here

关于react-native - react native : Animation not working properly on android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47278781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com