StackActions.drawToTop
Serhii Palash
We have a case when we need to take the screen from deep inside the stack navigator, if it's there, and push it on top of the stack. If screen is not already in the stack, just push it on top (navigate).
I was able to do this by adding
getId={() => 'menu'}
prop to <Stack.Screen ... />
in our app navigator, to prevent more than one 'menu' screen in the stack, and then calling navigation.dispatch(StackActions.push('menu'))
. The problems with this approach are- doesn't animate the transition to 'menu' when it's already in the stack
- requires special AppNavigator configuration with getIdprop
It would be nice to have it working (always with animation) with just one line of code
navigation.dispatch(StackActions.drawToTop('menu'))
Thanks in advance!
Serhii Palash
Or maybe name the new action just
draw
...navigation.dispatch(StackActions.draw('menu'))