Yas*_*sir 1 react-native react-animated
我一直试图修复过去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>
);
}
Run Code Online (Sandbox Code Playgroud)
这个组件是子组件,在父组件中使用如下:<FeedBack ref={ref => this.feedback = ref}/>没有任何条件要检查显示与否(因为构造函数中的动画比例设置为零,所以不需要)
toggle()当按下按钮时,从父进程调用该方法.
现在this works fine on iOS,当组件加载时,在按下按钮(然后缩放)之前视图不存在.但是android当组件加载时,视图已经存在.当我按下按钮时,动画视图会消失并重新出现(使用动画缩放),随后的切换工作正常.android中的问题是,即使initialValue比例为零,视图在第一次加载时仍然存在.
| 归档时间: |
|
| 查看次数: |
7971 次 |
| 最近记录: |