forked from shadowfacts/Tusker
Fix search results always pushing new column in multi-column nav
Closes #498
This commit is contained in:
parent
cee4e15b06
commit
2f31b50a5b
|
@ -59,7 +59,7 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate, Collect
|
|||
|
||||
resultsController = SearchResultsViewController(mastodonController: mastodonController)
|
||||
resultsController.exploreNavigationController = self.navigationController!
|
||||
searchController = MastodonSearchController(searchResultsController: resultsController)
|
||||
searchController = MastodonSearchController(searchResultsController: resultsController, owner: self)
|
||||
definesPresentationContext = true
|
||||
|
||||
navigationItem.searchController = searchController
|
||||
|
|
|
@ -34,7 +34,7 @@ class InlineTrendsViewController: UIViewController {
|
|||
|
||||
resultsController = SearchResultsViewController(mastodonController: mastodonController)
|
||||
resultsController.exploreNavigationController = self.navigationController
|
||||
searchController = MastodonSearchController(searchResultsController: resultsController)
|
||||
searchController = MastodonSearchController(searchResultsController: resultsController, owner: self)
|
||||
searchController.obscuresBackgroundDuringPresentation = true
|
||||
searchController.hidesNavigationBarDuringPresentation = false
|
||||
definesPresentationContext = true
|
||||
|
|
|
@ -24,7 +24,11 @@ class MastodonSearchController: UISearchController {
|
|||
super.searchResultsController as! SearchResultsViewController
|
||||
}
|
||||
|
||||
init(searchResultsController: SearchResultsViewController) {
|
||||
private weak var owner: UIViewController?
|
||||
|
||||
init(searchResultsController: SearchResultsViewController, owner: UIViewController) {
|
||||
self.owner = owner
|
||||
|
||||
super.init(searchResultsController: searchResultsController)
|
||||
|
||||
searchResultsController.tokenHandler = { [unowned self] token, op in
|
||||
|
@ -152,6 +156,12 @@ extension MastodonSearchController: UISearchBarDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
extension MastodonSearchController: MultiColumnNavigationCustomTargetProviding {
|
||||
var multiColumnNavigationTargetViewController: UIViewController? {
|
||||
owner
|
||||
}
|
||||
}
|
||||
|
||||
extension UISearchBar {
|
||||
var searchQueryWithOperators: String {
|
||||
var parts = searchTextField.tokens.compactMap { $0.representedObject as? String }
|
||||
|
|
|
@ -8,6 +8,13 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
/// View controllers, such as `UISearchController`, that live outside the normal VC hierarchy
|
||||
/// can adopt this protocol to indicate to `MultiColumnNavigationController` the context for
|
||||
/// navigation operations.
|
||||
protocol MultiColumnNavigationCustomTargetProviding {
|
||||
var multiColumnNavigationTargetViewController: UIViewController? { get }
|
||||
}
|
||||
|
||||
class MultiColumnNavigationController: UIViewController {
|
||||
|
||||
private var isManuallyUpdating = false
|
||||
|
@ -99,6 +106,8 @@ class MultiColumnNavigationController: UIViewController {
|
|||
index = _viewControllers.firstIndex(of: c)
|
||||
if index != nil {
|
||||
break
|
||||
} else if let targetProviding = c as? MultiColumnNavigationCustomTargetProviding {
|
||||
current = targetProviding.multiColumnNavigationTargetViewController
|
||||
} else {
|
||||
current = c.parent
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue