Imagine you have this navigation system:
-TabNavigator
--TabA
---StackNavigatorA
----ScreenA
----StackNavigatorB
--TabB
---StackNavigatorB
----ScreenB
Is there any way, using React Navigation 5, to get the closest parent navigator name? For example, if I am in the screen "ScreenA" and execute the method I need, this will return "StackNavigatorA"
Something like this:
const currentNavigator = navigation.getCurrentNavigator(); // <--- getCurrentNavigator doesn't exist, this is pseudocode.
console.log(currentNavigator); // Will show the closest parent navigator
Thank you.
To get closest navigation parent you can use dangerouslyGetParent() from navigation prop.
Also, "This method will return undefined if there is no parent navigator. Be sure to always check for undefined when using this method."
To check if navigator is its parents, you can define a custom key to each navigator to do your validations when necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With