software-mansion / react-native-screens

Native navigation primitives for your React Native app.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[native-stack] Focused search bar causes new screens to have incorrect header

nandorojo opened this issue · comments


I'm using the iOS search bar to search artists. Works as expected.

When you click on an artist, it opens the Artist screen.

The Artist screen has headerShown: false, since I have a custom header on that screen.

// this is the screen that search navigates to
    headerShown: false,
  getId={({ params }) => {
    return params?.slug

However, if I open the artist screen while the search bar is focused, it adds a header to the Artist screen, and creates a glitchy experience when I go back.



When the search bar is not focused, and I click an artist, it works normally. It navigates to the Artist screen, and there's no header.


Doesn't work

However, when the search bar is focused, it incorrectly adds a header to the Artist screen. Then, going back causes a weird jump.


Steps To Reproduce

  1. Create a native stack screen with a search bar
  2. Navigate to a screen that has headerShown: false while the search bar is focused.
  3. Try going back, too

Expected behavior

Having a searchBar should not add a header when opening a screen that has headerShown: false.

Actual behavior

A focused searchBar causes screens opened to have a header. It also causes a layout glitch when you go back. I have contentInsetAdjustmentBehavior="automatic" on my ScrollView like I saw in the TestExample file.

Snack or minimal code example

Expo Snack doesn't support 3.4.0. Let me know if you need me to make a full reproduction.

Package versions

  • React: 16.8.3
  • React Native: 0.63.4
  • React Native Screens: 3.4.0

Setting searchBar.hideNavigationBar: false makes the header bug go away. However, going back still causes the layout shift if the search bar was focused before opening the artist screen.

Also, I'd prefer to have hideNavigationBar: true. But I'll leave it false for now as a workaround.


i'm having same problem. Is it caused by createNativeStackNavigator() ?

@nandorojo Thanks for finding it. Unfortunately this is a native iOS issue stack overflow.

There is no easy fix on our side and we don't want to introduce very complex native logic to create workaround.

After inspecting this issue I came up with a JS workaround that should work for you.

If it works for you, please let us know.

What you can also do is wrap content in <ScrollView contentInsetAdjustmentBehavior="automatic">. Then set headerTranslucent: true and optionally searchBar.hideWhenScrolling: false. This should fix the layout shift.

I’ll try this, thanks!

If it works for you, please let us know.

Additionally #1153 is fixing the header bug, so you can test it too

@Ubax the solution in #1153 is better for me - I prefer it working without the custom work around. Thank you for that PR! Will keep testing

@nandorojo I merged #1153 and therefore I am closing the issue.
If there are still some problems please let us know.