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

Providing an action to navigate is never dispatched, while trying to replace a screen #5338

Closed
janhesters opened this issue Dec 5, 2018 · 6 comments

Comments

@janhesters
Copy link

janhesters commented Dec 5, 2018


Current Behavior

  • What code are you running and what is happening?

I have a Stack with three screens (Root, First and Second). I'm trying to follow the docs to navigate to a screen while simultaneously dispatching a navigation action.

The goal is to navigate from the root screen to the first screen. After wards navigate from the First screen to the Second screen, but have the back button point to the HomeScreen again (as if the First screen never was in the stack in the first place).

Using the action parameter I'm trying to dispatch a stack action to reset the state to the desired state while the animation is playing.

The current behaviour is dependent on the way I attempt this. In the demo below you can read, see and try out all my attempts (on FirstScreen). It seems like the StackAction provided is never dispatched.

Expected Behavior

  • What do you expect should be happening?

What should be happening is the animation should play out and you should be able to directly go back from the SecondScreen to the HomeScreen, without crossing the FirstScreen.
- Include a screenshot if it makes sense.

How to reproduce

See my attempts at demo and corresponding bugs in the demo.

https://snack.expo.io/SklozIBJE

If this isn't a bug and I'm just not capable of understanding the API could you kindly give a example how one would achieve this? (It's entirely possible that this is not a bug, but I'm just bad at understanding the docs).

Your Environment

software version
react-navigation 2.18 and above
react-native 0.5.7.1
node v9.4.0
npm or yarn 6.4.1
@brentvatne
Copy link
Member

brentvatne commented Dec 5, 2018

you can use getStateForAction to implement a way to control exactly what the state is reset to. imo this is actually how reset should work, rather than it dispatching actions it should just say set the state to this. see FirstScreen, SecondScreen, and Navigation in https://snack.expo.io/@notbrent/awkward-peach for an example. i updated this to 3.x and did not test in 2.x because i don't take issues for 2.x anymore.

@brentvatne
Copy link
Member

also just wanted to mention that in the example 2 the replace action will attempt to replace SecondScreen with SecondScreen, so that's why you don't see anything happen

@janhesters
Copy link
Author

@brentvatne Thank you for your help!

@brentvatne
Copy link
Member

hmm it seems like my snack doesn't show the latest change i made to it :( if you need help figuring it out i can rewrite it, sorry

@brentvatne
Copy link
Member

brentvatne commented Dec 7, 2018

went ahead and rewrote it, should be fine now at https://snack.expo.io/@notbrent/reset-state

@janhesters
Copy link
Author

@brentvatne Wow, thank you. This helps me a lot!😊

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

No branches or pull requests

2 participants