Skip to content

Comments

fix(iOS): prevent search bar from reopening keyboard on header button press#3676

Open
just1and0 wants to merge 1 commit intosoftware-mansion:mainfrom
just1and0:fix/ios-search-bar-keyboard-reopen
Open

fix(iOS): prevent search bar from reopening keyboard on header button press#3676
just1and0 wants to merge 1 commit intosoftware-mansion:mainfrom
just1and0:fix/ios-search-bar-keyboard-reopen

Conversation

@just1and0
Copy link

@just1and0 just1and0 commented Feb 22, 2026

Description

Closes #3677.

When a screen has both a headerSearchBarOptions search bar and header buttons (e.g. headerRight), tapping a header button after dismissing the search bar keyboard causes the keyboard to reopen unexpectedly.

Repro steps:

  1. Have a screen with both a search bar and a header right button
  2. Tap the search bar to focus it (keyboard opens)
  3. Dismiss the keyboard (tap Cancel or tap away)
  4. Tap the header right button
  5. Bug: The keyboard opens again instead of just triggering the button action

Minimal reproduction: https://github.com/sbkl/sdk-55-header-right-button-opening-keyboard

Also reported on Expo: expo/expo#43198

Changes

Two fixes in the iOS native code:

  1. RNSScreenStackHeaderConfig.mm: Guard the navitem.searchController assignment to only occur when the value actually changes. Previously, this was unconditionally reassigned on every updateViewController call, which caused UIKit to re-activate the search bar and trigger the keyboard.

  2. RNSSearchBar.mm: In searchBarCancelButtonClicked:, also call resignFirstResponder on the actual _controller.searchBar (the native UISearchBar), not just on self (the RNSSearchBar wrapper). This ensures the search bar fully gives up keyboard focus when cancelled.

Before & after

Before (bug)

Screen.Recording.2026-02-17.at.9.09.11.AM.mov

After focusing and dismissing the search bar, tapping the header menu button reopens the keyboard.

After (fix)

After the fix, tapping the header menu button correctly triggers the menu action without reopening the keyboard.

Test plan

  • Added TestSearchBarKeyboardReopen.tsx in apps/src/tests/issue-tests/
  • Steps to test:
    1. Open the test screen (has a search bar + "Menu" header right button)
    2. Tap the search bar to focus it
    3. Dismiss the keyboard
    4. Tap the "Menu" button in the header
    5. Verify the keyboard does not reopen and the button action fires correctly

Checklist

  • Included code example that can be used to test this change.
  • Updated / created local changelog entries in relevant test files.
  • For visual changes, included screenshots / GIFs / recordings documenting the change.
  • For API changes, updated relevant public types.
  • Ensured that CI passes

… press

When a screen has both a search bar and header buttons, tapping a header
button after dismissing the search bar keyboard causes the keyboard to
reopen unexpectedly. This happens because:

1. updateViewController unconditionally reassigns navitem.searchController
   on every render cycle, causing UIKit to re-activate the search bar.
2. searchBarCancelButtonClicked does not resign first responder on the
   actual UISearchBar, only on the RNSSearchBar wrapper.

This commit guards the searchController assignment to only occur when the
value changes, and ensures the native search bar properly resigns first
responder when cancelled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS: Header button reopens keyboard after search bar is dismissed

1 participant