react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

[V2][Android] bottom tab, click on already selected tab doesn't pop it's stack

Open Zycon42 opened this issue 8 years ago • 9 comments

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.push so 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

Zycon42 avatar Aug 20 '18 15:08 Zycon42

any update on this? have you solved this @Zycon42

damathryx avatar Oct 02 '18 05:10 damathryx

i am using 2.0.2632. still doesn't behave like iOS bottomTab 😿

narodejesus avatar Oct 31 '18 02:10 narodejesus

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.

Zycon42 avatar Oct 31 '18 10:10 Zycon42

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.

Brianwebb22 avatar Nov 12 '18 17:11 Brianwebb22

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.

stale[bot] avatar Dec 12 '18 20:12 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Dec 19 '18 21:12 stale[bot]

+1

loga4 avatar May 22 '19 01:05 loga4

@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 avatar May 22 '19 08:05 guyca

@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)
          }
        }
      )
    }

esbenvb avatar Jul 25 '19 20:07 esbenvb