question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Description

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
<Screen
  name="Artist"
  component={ArtistScreen}
  options={{
    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.

Screenshots

Works

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.

Video: https://www.loom.com/share/174403203eb941f9a5731ba62253ab11

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.

Video: https://www.loom.com/share/8f8037145df649f880b891f52b099520

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Ubaxcommented, Sep 20, 2021

@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. https://gist.github.com/Ubax/086c18d07044ede728aa0ea8aa56b7d5

If it works for you, please let us know.

0reactions
Ubaxcommented, Oct 8, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

is there a 'fixed header' or 'sticky header' for react native?
I add the screenshot of wireframe that shows what I meant. You'll notice that the Search bar stays at the top regardless the...
Read more >
Native Stack Navigator | React Navigation
Search bars are rarely static so normally it is controlled by passing an object to headerSearchBarOptions navigation option in the component's body. You...
Read more >
A guide to React Native Navigation - LogRocket Blog
Now that we have the boilerplate ready, let's begin with the search screen. Every screen within the navigator will be given two props:....
Read more >
3 Ways to Hide Navigation Bar in React Native Application
Sometimes you don't want to have a navigation bar on the top of the screen so to hide the navigation bar we can...
Read more >
detachinactivescreens | The AI Search Engine You Control
Current Behavior I have a navigator stack navigator with the prop ... Navigator detachInactiveScreens={false} headerMode={'none'}> <StackNav.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found