Reputation: 154
I have the following nested navigators in my one of my app modules:
RootStackNavigator (modal)
|
|____MainStackNavigator (default)
| |
| |______TopTabNavigator
| | |
| | |_____Chat List Screen
| | |
| | |_____Random Screen
| |
| |______Chat Screen
|
|____NewChatStackNavigator (default)
|
|_____Select Chat Screen
|
|_____some more screens
There are two ways to reach the "Chat Screen": either by choosing a chat from the "Chat List Screen", or by selecting a chat from the "Select Chat Screen". In both cases I use the "navigate" function from the "useNavigation" hook to navigate to the desired screens by passing the name of the screen as my first argument.
The first option works fine, the second one is causing me a lot of trouble: when I press it, the modal screen closes and the app navigates to "Chat Screen" (expected and desired behaviour although I believe the modal screen closes after the next screen is loaded, the opposite would be expected), but then the "Chat Screen" becomes buggy and unresponsive, the back button (that returns to the "Top Tab Navigator") stops working, and when sliding to navigate back (to the "Top Tab Navigator", which is "under" the now closed modal NewChatStackNavigator), the app freezes and eventually crashes.
I believe Im missing something fundamental in how React Navigation works and I havent been able to figure it out. Could anyone explain what is happening ?
Thanks for the help !
Upvotes: 0
Views: 1788
Reputation: 154
A hacky solution that works for now is navigating back from the "Select Chat Screen" and setting a timeout of at least 800ms (any value below that does not work) to navigate to the Chat Screen.
Someone explained that the problem could be due to the fact that there is no back screen from the Chat Screen since navigating from the "Select Chat Screen" closes that modal screen first and thus leaves the "Chat Screen" without a back page. Although this answer would explain the freezing/crashing when navigating back from the "Chat Screen", it doesnt explain why navigating to the screen itself still causes the screen's features not to work properly (never loading messages - infinitely stuck loading, keyboard not dismissing when tapping on messages scoll view, etc.)
Upvotes: 1