Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ios/UIViewController+RNNOptions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions playground/ios/NavigationTests/UIViewController+RNNOptionsTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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