Reputation: 34830
I'm using React Navigation in my React Native app and I'm trying to change a tab programmatically.
Here is my code:
navigation.navigate('key of the tab route');
Whereas in my navigation objects' state (just pasted screenshot in case I might miss a detail if I just like the routes):
It works great (navigates to the correct tab) in iOS, whereas on Android nothing happens. It does something as it returns true
if I specify a correct route name and false
if I specify a non-existent one, but nothing happens on screen.
I'm on Android 8.0, React Native 0.59.9, React 16.8.6, React Navigation 3.11.0.
What am I doing wrong?
Upvotes: 1
Views: 1247
Reputation: 34830
It had nothing to do with React Navigation. I was trying to invoke a navigation tab change by deep linking, and my Android app wasn't configured to keep a single instance of the activity, and it was launching a new instance of the main activity (therefore, a new instance of my whole React Native app as it lives inside a single activity) and messing everything up.
I've added the following code to manifest as an attribute to my activity:
android:launchMode="singleTop"
And the problem went away.
Upvotes: 2