2

I am using Wix's react-native-navigation V2 in my app for Android. 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. And don't know how to do with redux.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Ahtesham Shah
  • 243
  • 2
  • 7
  • 31

1 Answers1

-1
    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()
        }
Himanshu Ahuja
  • 197
  • 1
  • 13