React-native-navigation: Navigation.events().bindComponent not working after setRoot for the second time

Created on 24 Aug 2019  路  5Comments  路  Source: wix/react-native-navigation

Issue Description

I've used setRoot when switching users in my app, but the problem is that after switching it seems that the navigation events doesn't bind again, so as a result non of the lifecycle methods (didAppear & didDisappear) works!
Does anybody know what could be the problem?


Environment

  • React Native Navigation version: 2.22.3
  • React Native version: 0.59.8
  • Platform(s) (iOS, Android, or both?): Tested only on Android
  • Device info (Simulator/Device? OS version? Debug/Release?): Google Nexus 5X Android 7.1.0 Genymotion Emulator - Debug & Release
馃彋 stale

Most helpful comment

Same here, because when you setRoot, componentDidMount of "new Component instance" call first, then componentWillUnmount of "old Component instance" call later, which trigger unmounted function of ComponentEventsObserver class (check code in react-native-navigation/events), which should remove all your listener.

Work around here, try to setRoot to some temp root screen, thanks for setRoot return Promise, so you can know setRoot complete, then you can set it to your real root screen.

All 5 comments

Same here, because when you setRoot, componentDidMount of "new Component instance" call first, then componentWillUnmount of "old Component instance" call later, which trigger unmounted function of ComponentEventsObserver class (check code in react-native-navigation/events), which should remove all your listener.

Work around here, try to setRoot to some temp root screen, thanks for setRoot return Promise, so you can know setRoot complete, then you can set it to your real root screen.

@phuhk thanks a lot, your solution worked

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

The issue has been closed for inactivity.

same issue

Was this page helpful?
0 / 5 - 0 ratings