【发布时间】:2017-11-14 06:09:54
【问题描述】:
过去 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 ,当组件加载时,视图不存在,直到按下按钮(然后缩放)。但是在android 上,当组件加载时,视图已经存在。当我按下按钮时,动画视图消失并重新出现(带有动画缩放),随后的切换工作正常。 android中的问题是即使initialValue的比例为零,第一次加载时视图仍然存在。
【问题讨论】:
标签: react-native react-animated