Handle navigation of dynamically generated stack navigator

47 Views Asked by At

I am trying to make/generate a kind of wizard / workflow stack navigator dynamically where some screens are optional and I need to find a way to navigate from a screen to next step in that wizard/workflow.

Usually I would just call navigation.navigate('NextStepScreen') from the current screen, but since the navigator is generated dynamically, screens inside of it do not know which step/screen is the next, only the navigator knows.

The 1st option is to pass the "next route" as prop to every screen component in the navigator using initialParams (maybe?), but then I would repeat in every screen the navigate call. Also I don't know what happens to initialParams if the actions performed by the user in the current screen changes what should be the next screen ? Is "initialParams" going to be refreshed like any state variable if navigator is re-rendered ? If so, it means I need a re-render of the whole navigator in order to get the "next screen" prop updated...

So I would prefer a 2nd option where I would be able to keep the navigate() call inside the navigator, but then I need a way to ask the navigator to navigate from the screen.

It seems it is not recommended to pass callbacks in screen props, so how should I do that ? an EventEmitter ?

0

There are 0 best solutions below