Skip to content

Commit a4a76c0

Browse files
authored
Merge pull request #181 from analogcode/dev
Fix stations search bar
2 parents 209f400 + ef9a5e7 commit a4a76c0

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

SwiftRadio/ViewControllers/StationsViewController.swift

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ class StationsViewController: UIViewController, Handoffable {
3535
// MARK: - UI
3636

3737
private let searchController: UISearchController = {
38-
return UISearchController(searchResultsController: nil)
38+
let controller = UISearchController(searchResultsController: nil)
39+
controller.obscuresBackgroundDuringPresentation = false
40+
controller.hidesNavigationBarDuringPresentation = true
41+
return controller
3942
}()
4043

4144
private let refreshControl: UIRefreshControl = {
@@ -244,37 +247,14 @@ extension StationsViewController: UISearchResultsUpdating {
244247
guard Config.searchable else { return }
245248

246249
searchController.searchResultsUpdater = self
247-
searchController.obscuresBackgroundDuringPresentation = false
248-
searchController.searchBar.sizeToFit()
249-
250-
// Add UISearchController to the tableView
251-
tableView.tableHeaderView = searchController.searchBar
252-
tableView.tableHeaderView?.backgroundColor = UIColor.clear
253-
definesPresentationContext = true
254-
searchController.hidesNavigationBarDuringPresentation = false
255-
256-
// Style the UISearchController
257-
searchController.searchBar.barTintColor = UIColor.clear
258-
searchController.searchBar.tintColor = UIColor.white
259-
260-
// Hide the UISearchController
261-
tableView.setContentOffset(CGPoint(x: 0.0, y: searchController.searchBar.frame.size.height), animated: false)
262-
// iOS 13 or greater
263-
if #available(iOS 13.0, *) {
264-
// Make text readable in black searchbar
265-
searchController.searchBar.barStyle = .black
266-
// Set a black keyborad for UISearchController's TextField
267-
searchController.searchBar.searchTextField.keyboardAppearance = .dark
268-
} else {
269-
let searchTextField = searchController.searchBar.value(forKey: "_searchField") as? UITextField
270-
searchTextField?.keyboardAppearance = .dark
271-
}
250+
navigationItem.searchController = searchController
251+
navigationItem.hidesSearchBarWhenScrolling = true
272252
}
273253

274254
func updateSearchResults(for searchController: UISearchController) {
275255
guard let filter = searchController.searchBar.text else { return }
276256
manager.updateSearch(with: filter)
277-
self.tableView.reloadData()
257+
tableView.reloadData()
278258
}
279259
}
280260

0 commit comments

Comments
 (0)