我有一个
View
在我想显示的React Native屏幕中,5秒钟后淡出。这是房间里的景色
render()
方法:
{this.state.showView (
<Animated.View style={{ opacity: this.state.fadeAnim }}>
</Animated.View>
)}
屏幕上有一个按钮,当我点击按钮时,我想在显示和隐藏视图之间切换。这里没有任何动画,但在视图显示5秒后,我想将其淡出。这是我在办公室里的东西
onPress()
按钮的事件。
onPress = () => {
if (this.state.showView) {
this.setState({
...this.state,
fadeAnim: new Animated.Value(0),
showView: false,
});
} else {
this.setState(
{
...this.state,
fadeAnim: new Animated.Value(1),
showView: true,
},
() => {
Animated.timing(this.state.fadeAnim, {
toValue: 0,
duration: 2000,
delay: 5000,
}).start(() => {
this.setState({
...this.state,
fadeAnim: new Animated.Value(0),
showView: false,
});
});
},
);
}
};
这不管用。视图按预期显示和消失,但不会淡出;它只是在没有动画的情况下消失。我做错了什么?