Skip to content

Commit

Permalink
fix(TVOS): fix crash with searchResultsController in RNSSearchBar (so…
Browse files Browse the repository at this point in the history
…ftware-mansion#2004)

## Description

On TVOS applications are crashing when user tries to open a screen with
Search Bar. This happens because TVOS requires UISearchController to
contain `searchResultsController`. this PR resolves it by adding simple
`UIViewController` as searchResultsController.

Fixes software-mansion#2003.

## Changes

- Fixed crash on TVOS when user tries to open screen with search bar.

## Screenshots / GIFs

### Before


https://github.com/software-mansion/react-native-screens/assets/23281839/4f7b727a-139e-45a0-8141-f40b3e45d101

### After

> [!WARNING]
Please keep in mind that the visible search bar on that video does not
belong to the original implementation on TVOS.

https://github.com/software-mansion/react-native-screens/assets/23281839/7138f27e-294b-4d66-b5aa-ff2745d0d406

## Checklist

- [X] Ensured that CI passes
  • Loading branch information
tboba authored and ja1ns committed Oct 9, 2024
1 parent 1a529be commit af8565c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ios/RNSSearchBar.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ - (instancetype)init

- (void)initCommonProps
{
#if !TARGET_OS_TV
_controller = [[UISearchController alloc] initWithSearchResultsController:nil];
#else
// on TVOS UISearchController must contain searchResultsController.
_controller = [[UISearchController alloc] initWithSearchResultsController:[UIViewController new]];
#endif

_controller.searchBar.delegate = self;
_hideWhenScrolling = YES;
_placement = RNSSearchBarPlacementStacked;
Expand Down

0 comments on commit af8565c

Please sign in to comment.