我正在Android的应用程序中使用Wix的react-native-navigation V2。当我按下一个屏幕时,在弹出或按下返回按钮之后,上一个或第一个组件不会渲染,也不会执行任何生命周期方法。即使我们不能在流行音乐中使用传递道具。我想刷新上一页,我该怎么做。我只是弹出如下屏幕
goBack = () => {
Navigation.pop(this.props.componentId);
}
我在GitHub https://github.com/wix/react-native-navigation/issues/2594上发现了此问题,他说可以通过使用Redux / MobX同步数据或听visibility events
来解决此问题,但在V2中没有发现可见性事件。而且不知道如何使用redux。
答案 0 :(得分:0)
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()
}