[英]How to refresh the first screen after poping the second screen from stack react-native-navigation V2?
I am using Wix's react-native-navigation V2 in my app for Android. 我在Android应用中使用Wix的react-native-navigation V2。 When I am pushing one screen and after a pop or pressing back button the previous or first component not rendering and not executing any lifecycle method.
当我按下一个屏幕时,在弹出或按下返回按钮之后,上一个或第一个组件不会渲染,也不会执行任何生命周期方法。 Even we cannot use pass props in pop.
即使我们不能在流行音乐中使用传递道具。 I want to refresh that previous page how can I do that.
我想刷新上一页,我该怎么做。 I am just poping the screen as below
我只是弹出屏幕如下
goBack = () => {
Navigation.pop(this.props.componentId);
}
I found this issue on GitHub and it is saying that this problem could be solved by either syncing the data using Redux/MobX or listen to visibility events
but I didn't found visibility events in V2. 我在GitHub上发现了此问题,这是说可以通过使用Redux / MobX同步数据或侦听
visibility events
来解决此问题,但我在V2中没有发现可见性事件。 And don't know how to do with redux. 而且不知道如何使用redux。
You can follow the below steps to do so:
1). Subscribe for react-navigation's 'didFocus' event in the component's constructor(or componentDidMount or componentWillMount).
// Subscribe for Event
constructor(props) {
super(props)
this.didFocusSubscription = this.props.navigation.addListener(
'didFocus',
payload => {
// Refresh your screen here
}
);
}
2). Do not forget to unsubscribe the event when the component will unmount.
// UnSubscribe for Event
componentWillUnmount = () => {
this.didFocusSubscription.remove()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.