Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request - popToTop() in other routes #8988

Closed
VictorioMolina opened this issue Oct 24, 2020 · 5 comments
Closed

Feature request - popToTop() in other routes #8988

VictorioMolina opened this issue Oct 24, 2020 · 5 comments

Comments

@VictorioMolina
Copy link

VictorioMolina commented Oct 24, 2020

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.

Related with: #5114 #6639

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

@github-actions
Copy link

Couldn't find version numbers for the following packages in the issue:

  • @react-navigation/native

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

@github-actions
Copy link

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/material-bottom-tabs (found: 5.2.5, latest: 5.2.19)
  • @react-navigation/native (found: 5.4.0, latest: 5.7.6)
  • @react-navigation/stack (found: 5.3.7, latest: 5.9.3)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@github-actions
Copy link

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/material-bottom-tabs (found: 5.2.19, latest: 5.3.0)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@github-actions
Copy link

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/compat (found: 5.2.8, latest: 5.3.0)
  • @react-navigation/material-bottom-tabs (found: 5.2.19, latest: 5.3.0)
  • @react-navigation/native (found: 5.7.6, latest: 5.8.0)
  • @react-navigation/stack (found: 5.9.3, latest: 5.10.0)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@VictorioMolina
Copy link
Author

I wrote a solution in the stackoverflow question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant