From da25f5dc48ffa4f9fefccc3aa99179aa7d8ccaed Mon Sep 17 00:00:00 2001 From: Isaac Israel Date: Mon, 1 Jun 2026 11:42:40 +0300 Subject: [PATCH 1/2] fix(ios): handle searchBar focus on mergeOptions for existing searchController When calling mergeOptions with searchBar.focus: true on a screen that already has a searchController, the focus was silently ignored because the focus logic only ran in the initial creation branch. This adds focus handling in the else branch so becomeFirstResponder is called on existing search controllers, enabling re-focus on screen reappear (e.g. switching back to a bottom tab). Fixes #8318 Co-authored-by: Cursor --- ios/UIViewController+RNNOptions.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ios/UIViewController+RNNOptions.mm b/ios/UIViewController+RNNOptions.mm index 5c79b2fdac..59ffae5701 100644 --- a/ios/UIViewController+RNNOptions.mm +++ b/ios/UIViewController+RNNOptions.mm @@ -94,6 +94,12 @@ - (void)setSearchBarWithOptions:(NSString *)placeholder } } #endif + if (focus) { + dispatch_async(dispatch_get_main_queue(), ^{ + self.navigationItem.searchController.active = true; + [self.navigationItem.searchController.searchBar becomeFirstResponder]; + }); + } } } From d88c98bd79bd7562a03850aac8f3a21a7e432ffd Mon Sep 17 00:00:00 2001 From: Yedidya Kennard Date: Tue, 2 Jun 2026 14:11:33 +0300 Subject: [PATCH 2/2] test(ios): cover refocusing existing search controller --- .../UIViewController+RNNOptionsTest.mm | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/playground/ios/NavigationTests/UIViewController+RNNOptionsTest.mm b/playground/ios/NavigationTests/UIViewController+RNNOptionsTest.mm index 2ab918ca79..89211a1739 100644 --- a/playground/ios/NavigationTests/UIViewController+RNNOptionsTest.mm +++ b/playground/ios/NavigationTests/UIViewController+RNNOptionsTest.mm @@ -77,4 +77,25 @@ - (void)testSetBackgroundImageShouldAddUIImageViewSubviewWithImage { XCTAssertEqual(imageView.image, image); } +- (void)testSetSearchBarWithOptionsWithExistingSearchControllerAndFocusShouldFocusSearchBar { + UIViewController *viewController = [UIViewController new]; + UISearchController *searchController = [UISearchController new]; + id searchBar = [OCMockObject partialMockForObject:searchController.searchBar]; + viewController.navigationItem.searchController = searchController; + + [[searchBar expect] becomeFirstResponder]; + + [viewController setSearchBarWithOptions:nil + focus:YES + hideTopBarOnFocus:NO + hideOnScroll:NO + obscuresBackgroundDuringPresentation:NO + backgroundColor:nil + tintColor:nil + cancelText:nil + placement:SearchBarPlacementStacked]; + + [searchBar verifyWithDelay:1]; +} + @end