我对动画有点问题。我尝试在我的应用程序上执行Flash Bar Info以获取错误。为此,我创建了一个新组件,可以将该组件放置在一个特定的视图中,也可以不放置在一个特定的视图中,并且当我的商店触发错误时,componentWillReceiveProps如果有错误消息,则该组件的状态将被更改并设置为可见。
因此,如果没有错误消息,我的渲染函数返回false值,但是如果有错误消息,我使用以下动画代码运行渲染函数:
// Ease in ease out anitmation
Animated.sequence([
Animated.timing(this.state.translateY, {
toValue: 40,
easing: Easing.bounce, // Like a ball
duration: 450,
}),
Animated.delay(3000),
Animated.timing(this.state.translateY, {
toValue: 0,
duration: 300,
}),
]).start(() => {
this.props.clearMessage();
this.setState({ visible: false }); // <-- Problem is here
});
Run Code Online (Sandbox Code Playgroud)
如果在动画延迟期间停留在视图上,则效果很好,但是如果在将消息设置为可见时转到上一个视图,setState则在未安装组件时调用该函数。所以我得到了警告:
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for …Run Code Online (Sandbox Code Playgroud)