[V2][Android] bottom tab, click on already selected tab doesn't pop it's stack
Issue Description
When we have BottomTabs and one tab contains stack of multiple screens, and that tab is currently selected. Expectation is that if user selects already selected tab and this tab has some screens pushed, it will "popToRoot". Currently iOS behaves like that out of the box, but android does not.
Related issue is that android doesn't send BottomTabSelected event in this situation but iOS does. So it's not possible to use some workaround on JS side, because tab "reselects" are not send to JS on android.
Steps to Reproduce / Code Snippets / Screenshots
- Have an app with BottomTabs, screens Tab1|Tab2|Tab3
- On first tab push screen using
Navigation.pushso we have Tab1 > Screen1 | Tab2 | Tab3 - Click on first tab icon
Actual: Nothing happens
Expected: Screen1 is poped and navigation state is back to Tab1|Tab2|Tab3
Environment
- React Native Navigation version: 2.0.2452
- React Native version: 0.56.0
- Platform(s) (iOS, Android, or both?): Android
- Device info (Simulator/Device? OS version? Debug/Release?): Samsung s8, android 8.0, Debug&Release
any update on this? have you solved this @Zycon42
i am using 2.0.2632. still doesn't behave like iOS bottomTab 😿
I believe issue with BottomTabSelected event not being send was fixed, so now you can develop js workaround.
We use patch-package to patch RNN directly, I think our solution is rather a dirty hack because I don't know RNN internals enough, so I didn't submit PR. Our patch for anyone interested.
I believe issue with BottomTabSelected event not being send was fixed, so now you can develop js workaround.
We use patch-package to patch RNN directly, I think our solution is rather a dirty hack because I don't know RNN internals enough, so I didn't submit PR. Our patch for anyone interested.
I manually implemented this change as a test and it worked for me. Thanks for sharing. Checking out patch-package now.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.
The issue has been closed for inactivity.
+1
@loga4 This isn't the default BottomTabs behaviour on Android. But you can easily achieve this with a bottomTabSelectedListener - keep track of the current tab and call Navigation.popToRoot when selectedTabIndex equals unselectedTabIndex
@guyca thanks for the suggestion :)
I was able to fix it by adding this piece of code right after my Navigation.setRoot({root: {bottomTabs: {...}}})
if (Platform.OS === 'android') {
Navigation.events().registerBottomTabSelectedListener(
async ({ selectedTabIndex, unselectedTabIndex }) => {
if (
selectedTabIndex === Tabs.Stats &&
unselectedTabIndex === Tabs.Stats
) {
await Navigation.popToRoot(ScreenNames.StatsScreen)
}
}
)
}