Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search bar on Android incorrectly adjusts other header elements when open #1450

Closed
2 of 7 tasks
nrwinner opened this issue May 17, 2022 · 10 comments · Fixed by #1903
Closed
2 of 7 tasks

Search bar on Android incorrectly adjusts other header elements when open #1450

nrwinner opened this issue May 17, 2022 · 10 comments · Fixed by #1903
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided

Comments

@nrwinner
Copy link

Description

On Android, the search bar does not properly adjust header elements.

  • Elements placed via headerRight are "pushed" out of the way and to the left of the search bar
  • If there are any elements placed via headerLeft, both the screen title and said elements are not adjusted at all and appear under the search bar

Screenshots

Screen Shot 2022-05-17 at 10 33 52 AM

Screen Shot 2022-05-17 at 10 34 05 AM

Steps To Reproduce

  1. Add a search bar to the header by specifying headerSearchBarOptions
  2. Add any element(s) via the headerLeft navigation option
  3. (Optional) Add any elements to the headerRight navigation option
  4. Open the search bar on android

Expected behavior

  • The header buttons on both the left side and the right side should no longer be visible.
  • The search bar should appear as the only element in the header.
  • The input should be unobstructed.

Actual behavior

  • Any elements placed via headerRight seem to get "pushed" out of the way to the left of the search bar
  • The screen title as well as any elements placed by headerLeft are not adjusted and appear under the search bar

Reproduction

https://snack.expo.dev/@nrwinner/android-search-bug---react-native-screens-repro

Platform

  • iOS
  • Android
  • Web
  • Windows
  • tvOS

Workflow

  • Managed workflow
  • Bare workflow

Package versions

package version
react-native 0.68.1
@react-navigation/native 6.0.2
@react-navigation/native-stack 6.1.0
react-native-screens 3.13.1
react-native-safe-area-context 4.2.4
expo 45.0.0
@github-actions github-actions bot added Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided labels May 17, 2022
@hirbod
Copy link
Contributor

hirbod commented May 27, 2022

I can confirm this issue. Forced me to remove searchHeader completely

@nrwinner nrwinner changed the title Search bar on Android incorrectly adjust other header elements when open Search bar on Android incorrectly adjusts other header elements when open May 29, 2022
@wem2017
Copy link

wem2017 commented Sep 7, 2022

I face the same issue, thanks for your feedback

Screenshot_20220907_204736
Screenshot_20220907_204721

@EliasBarrera
Copy link

could you find a solution ?

@nrwinner
Copy link
Author

@EliasBarrera I used the onOpen and onClose callbacks from the search bar to hide the header buttons while the search bar is open. Less than ideal and kinda laggy but it's the best I could do until this gets fixed.

@EliasBarrera
Copy link

Thank you! :D

@mazurGit
Copy link

mazurGit commented Oct 7, 2022

You can try to place component on headerRight instead of headerLeft and add marginRight to it :
const {width} = Dimensions.get('screen');
...
headerRight:() => <FiltersHeader contentContainerStyle={{marginRight: width - 110}} />

2022-10-08.at.02-42-44.mp4

@garrettg123
Copy link

Talk about a second-class citizen called Android. This still exists... Here's how I've implemented @nrwinner's idea:

  useLayoutEffect(() => {
    navigation.setOptions({
      headerSearchBarOptions: {
        onOpen: () => {
          setIsSearchBarOpen(true)
        },
        onClose: () => {
          setIsSearchBarOpen(false)
        },
      },
      headerLeft: isSearchBarOpen ? () => null : undefined,
      headerBackVisible: isSearchBarOpen ? false : true,
      headerTitle: isSearchBarOpen ? '' : undefined,
    })
  }, [navigation, isSearchBarOpen])

@tboba
Copy link
Member

tboba commented Sep 27, 2023

Hi @nrwinner, thanks for reporting that! Sorry for the really late response 🙏
I've managed to reproduce this problem and successfully fixed that! I'll create a PR shortly 🥳

tboba added a commit that referenced this issue Sep 30, 2023
## Description

Currently, when user opens the search bar all of the subviews on the
toolbar are being pushed to the left.
Instead, we want to hide them or even remove them so that they won't be
visible during the layout.
This PR fixes that problem by secretly hiding the toolbar elements,
changing their visibility to `GONE`.

Fixes #1450.

## Changes

- Added a fix that is being controlled by `handleOpen` and `handleClose`
methods in SearchBarView.

## Screenshots / GIFs

### Before


https://github.com/software-mansion/react-native-screens/assets/23281839/8ca8e18e-2cf6-4c04-85c8-51b5d69f1a61

### After


https://github.com/software-mansion/react-native-screens/assets/23281839/41330ea7-a12b-4e14-9a1e-2207a54ebed0

## Test code and steps to reproduce

In our example app open `SearchBar.tsx` and add `headerRight: () =>
<Button title="Test"/> to the `navigation.setOptions({` declaration.
Then launch the app and open `Search bar` example.

## Checklist

- [ ] Ensured that CI passes
@tboba
Copy link
Member

tboba commented Oct 17, 2023

Hi @nrwinner @garrettg123 @EliasBarrera @wem2017 @hirbod, there's a new version of react-native-screens: 3.26.0 which has this change included. Check it out! If you find something wrong related to the newest version (this change is still buggy or doesn't work for you) let us know 🎉

@hirbod
Copy link
Contributor

hirbod commented Oct 17, 2023

Great, we actually have a use case for this so I am keen to try it

ja1ns pushed a commit to WiseOwlTech/react-native-screens that referenced this issue Oct 9, 2024
…-mansion#1903)

## Description

Currently, when user opens the search bar all of the subviews on the
toolbar are being pushed to the left.
Instead, we want to hide them or even remove them so that they won't be
visible during the layout.
This PR fixes that problem by secretly hiding the toolbar elements,
changing their visibility to `GONE`.

Fixes software-mansion#1450.

## Changes

- Added a fix that is being controlled by `handleOpen` and `handleClose`
methods in SearchBarView.

## Screenshots / GIFs

### Before


https://github.com/software-mansion/react-native-screens/assets/23281839/8ca8e18e-2cf6-4c04-85c8-51b5d69f1a61

### After


https://github.com/software-mansion/react-native-screens/assets/23281839/41330ea7-a12b-4e14-9a1e-2207a54ebed0

## Test code and steps to reproduce

In our example app open `SearchBar.tsx` and add `headerRight: () =>
<Button title="Test"/> to the `navigation.setOptions({` declaration.
Then launch the app and open `Search bar` example.

## Checklist

- [ ] Ensured that CI passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants