Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search bar selection and rotation fixes #345

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ extension FilesViewController : UISearchBarDelegate, UISearchControllerDelegate
}

func willDismissSearchController(_ searchController: UISearchController) {
addSearchBarButton()
self.navigationItem.searchController = nil
self.navigationController?.view.setNeedsLayout()
self.navigationController?.view.layoutIfNeeded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener {
}

func setupSearchBar(){
addSearchBarButton()
let searchButton = UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(searchTapped))
self.navigationItem.rightBarButtonItem = searchButton

searchController = UISearchController(searchResultsController: nil)
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search"
Expand All @@ -306,39 +308,23 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener {
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [.foregroundColor: UIColor.label]
} else {
searchController.searchBar.tintColor = .white
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [.foregroundColor: UIColor.white]
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [.foregroundColor: UIColor.white]

}

searchController.delegate = self
searchController.searchBar.delegate = self
searchController.hidesNavigationBarDuringPresentation = false

definesPresentationContext = true
navigationController?.view.backgroundColor = self.view.backgroundColor
}

@objc func searchTapped(){
self.navigationItem.searchController = searchController
self.navigationItem.hidesSearchBarWhenScrolling = false
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.isTranslucent = true
searchController.isActive = true

removeSearchBarButton()
}

func addSearchBarButton(){
let searchButton = UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(searchTapped))
if self.navigationItem.rightBarButtonItems != nil && self.navigationItem.rightBarButtonItems!.count > 0{
self.navigationItem.rightBarButtonItems?.insert(searchButton, at: 0)
}else{
self.navigationItem.rightBarButtonItem = searchButton
}
}

func removeSearchBarButton(){
if self.navigationItem.rightBarButtonItems?.count == 1{
self.navigationItem.rightBarButtonItem = nil
}else{
self.navigationItem.rightBarButtonItems?.remove(at: 0)
}
}

override func viewWillDisappear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class OfflineFilesViewController: BaseUIViewController{
self.navigationItem.searchController = searchController
self.navigationItem.hidesSearchBarWhenScrolling = false
self.navigationItem.rightBarButtonItem = nil
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.isTranslucent = true
searchController.isActive = true
}

Expand Down