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

Header back button missing when navigating from root to a nested stack where root-stack has `headerShown` set to false

Open hirbod opened this issue 2 years ago • 22 comments

Description

Hi @WoLewicki, I have following issue.

Following scenario (pseudo):

   RootStack (headerShown: false)
       BottomTabsNavigator
       StackNavigator1 (headerShown: true, since I want to maintain the own stack)
       StackNavigator2 (headerShown: true, since I want to maintain the own stack)
       StackNavigator3 (headerShown: true, since I want to maintain the own stack)

These stacks are placed inside root stack but not in BottomTabs, since we want them to be placed above the BottomTabs

No issues so far. The real issue is that since we've disabled headerShown for RootStack, because our child stacks need to maintain there own header, the back button is missing when I navigate to StackNavigator1, 2 or 3.

I made some tests (canGoBack() and goBack/pop). All methods work, canGoBack returns true. The navigator is actually aware that it CAN go back, but you're disabling the back button at this place. I also talked with @satya164 and tested the JSStack and it is handled correctly there, where the back button won't be removed.

Currently, I am forced to use headerLeft and insert my own back button. While basically no big deal, the real issue is that headerLeft position is not the exact same position as the native back button (native back button is like 8px from left, while headerLeft starts at around 20px) and that when you try to achieve the same look across the app, you would need to to apply a left: -12. The problem with that is again, that the back button gets cut-off while animating the header between navigation. Thats an issue for itself but this also describes why I don't want to add headerLeft manually.

The issue does not appear when we enable the header in RootStack, but that is not what we want. We want that each child-nest-stack to handle its own header and logic.

Screenshots

Steps To Reproduce

  1. I already described everything
  2. There is a snack available

Expected behavior

Native back button should appear, should be handled like in the JS-Stack.

Actual behavior

Back button is hidden, even though canGoBack returns true

Reproduction

https://snack.expo.dev/@hirbod/native-stack-header-issues---back-button-missing

I made this snack interactive. Please click through it and take notes on the text. While reproducible in web as well, please also test on iOS and Android, there are extra issues.

Platform

  • [x] iOS
  • [x] Android
  • [x] Web
  • [ ] Windows
  • [ ] tvOS

Workflow

  • [x] Managed workflow
  • [x] Bare workflow

Package versions

package version
react-native 0.68.2
@react-navigation/native 6
@react-navigation/native-stack 6
react-native-screens 3.13
react-native-safe-area-context 4.2.4
react-native-gesture-handler 2.4.2
react-native-reanimated 2.8.0
expo 45

hirbod avatar May 29 '22 06:05 hirbod

Does the back button not appear on Android too? On iOS I am afraid it is not possible to achieve the native header back button in such case since it is a native prop based on if we are deeper in stack and since the nested stack has only one screen pushed at the beginning, there is nowhere to go back in it. JS stack adds does not use native header so it can add such button on demand.

WoLewicki avatar Jun 01 '22 13:06 WoLewicki

It looks like on Android the back button is visible: image

WoLewicki avatar Jun 01 '22 13:06 WoLewicki

You're right, android works. iOS not. But the same goes for web.

To be honest, I am pretty confident that this is doable on iOS. The stack is aware that it can return, even gestures do work. I can't imagine that there is no way to make the header show that icon.

hirbod avatar Jun 01 '22 16:06 hirbod

And what is still unanswered: why is header left and header right wrongly positioned and gets cut off when changing the left value while animation. The insets applied are not correct

hirbod avatar Jun 01 '22 16:06 hirbod

The stack is aware that it can return, even gestures do work

The gesture likely works because the screen the stack is nested in is aware that it can go back with a gesture and it handles the gesture, but the nested stack itself isn't aware.

satya164 avatar Jun 02 '22 15:06 satya164

So you think it is not possible to make the nested stack aware of it (maybe a flag which tells it to show the back button unless headerLeft is set)

hirbod avatar Jun 02 '22 17:06 hirbod

Unless the native UINavigationController supports it then there's no other way than a custom header (or fix that issue you have with the custom back button if possible)

satya164 avatar Jun 02 '22 17:06 satya164

Fixing the insets or clipping of headerLeft and headerRight would be indeed an feasible solution

hirbod avatar Jun 03 '22 04:06 hirbod

Also experiencing this issue. Any help would be greatly appreciated if it's possible.

maxckelly avatar Jun 08 '22 10:06 maxckelly

@WoLewicki as talked at appjsconf, here is the small "hint/comment/ping" regarding the inset issue. :) Once again, was a pleasure to meet you in person!

hirbod avatar Jun 12 '22 11:06 hirbod

I will try to look into it as fast as possible, hopefully all Fabric issues in the repo are gone soon 😅 It was great to meet one of the main contributors to the library too!

WoLewicki avatar Jun 21 '22 14:06 WoLewicki

I'm upgrading React Navigation from version 3 to 6 and facing the same issue. Any updates about this fix or hints about what to do?

gui-grana avatar Aug 17 '22 00:08 gui-grana