Description
In my app I have a bottom tab navigator, and in each tab, I have a stack navigator in each tab.
Is it possible to do .popToTop() over a specific tab's stack from another tab? I mean, for example, if I am in a stack screen "Camera" from one tab, and I navigate to the "Profile" stack screen which is in another tab and has other screens pushed over its root, obviously, I will see these other screens (the state is not resetted)... but doing popToTop() in this specific route (the "Profile" screen) doesn't work for me because I lose all the params that was sent from the "Camera" screen when navigating (the intention was to send them to the root)...
I think this will be great to have something like .popToTop("route-name"); so we can perform this action over any other route.
Maybe, the workaround is to do CommonActions.reset({}), but I don't find any example for React Navigation 5.
The main problem: Reset a stack from another stack before navigating to it.
What I have tried
const resetAction = CommonActions.reset({
index: 0,
actions: [
navigation.navigate("Profile", {
screen: "Profile",
params: { post },
}),
],
});
navigation.dispatch(resetAction);
In the Camera Screen, but I get the error "TypeError: undefined is not an object (evaluating 'nextState.routes.length')"
Full problem explained with a workaround
The main problem is what I have explained avobe, but here I explain my use case and my navigation structure better:
https://stackoverflow.com/questions/64515420/react-navigation-5-reset-a-stack-poptotop-from-another-stack-before-naviga
Current versions I am using:
@react-navigation/compat: 5.2.8
@react-navigation/material-bottom-tabs: 5.2.19
@react-navigation/native: 5.7.6
@react-navigation/stack: 5.9.3