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 = SearchResultsViewController(mastodonController: mastodonController)
|
||||||
resultsController.exploreNavigationController = self.navigationController!
|
resultsController.exploreNavigationController = self.navigationController!
|
||||||
searchController = MastodonSearchController(searchResultsController: resultsController)
|
searchController = MastodonSearchController(searchResultsController: resultsController, owner: self)
|
||||||
definesPresentationContext = true
|
definesPresentationContext = true
|
||||||
|
|
||||||
navigationItem.searchController = searchController
|
navigationItem.searchController = searchController
|
||||||
|
|
|
@ -34,7 +34,7 @@ class InlineTrendsViewController: UIViewController {
|
||||||
|
|
||||||
resultsController = SearchResultsViewController(mastodonController: mastodonController)
|
resultsController = SearchResultsViewController(mastodonController: mastodonController)
|
||||||
resultsController.exploreNavigationController = self.navigationController
|
resultsController.exploreNavigationController = self.navigationController
|
||||||
searchController = MastodonSearchController(searchResultsController: resultsController)
|
searchController = MastodonSearchController(searchResultsController: resultsController, owner: self)
|
||||||
searchController.obscuresBackgroundDuringPresentation = true
|
searchController.obscuresBackgroundDuringPresentation = true
|
||||||
searchController.hidesNavigationBarDuringPresentation = false
|
searchController.hidesNavigationBarDuringPresentation = false
|
||||||
definesPresentationContext = true
|
definesPresentationContext = true
|
||||||
|
|
|
@ -24,7 +24,11 @@ class MastodonSearchController: UISearchController {
|
||||||
super.searchResultsController as! SearchResultsViewController
|
super.searchResultsController as! SearchResultsViewController
|
||||||
}
|
}
|
||||||
|
|
||||||
init(searchResultsController: SearchResultsViewController) {
|
private weak var owner: UIViewController?
|
||||||
|
|
||||||
|
init(searchResultsController: SearchResultsViewController, owner: UIViewController) {
|
||||||
|
self.owner = owner
|
||||||
|
|
||||||
super.init(searchResultsController: searchResultsController)
|
super.init(searchResultsController: searchResultsController)
|
||||||
|
|
||||||
searchResultsController.tokenHandler = { [unowned self] token, op in
|
searchResultsController.tokenHandler = { [unowned self] token, op in
|
||||||
|
@ -152,6 +156,12 @@ extension MastodonSearchController: UISearchBarDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension MastodonSearchController: MultiColumnNavigationCustomTargetProviding {
|
||||||
|
var multiColumnNavigationTargetViewController: UIViewController? {
|
||||||
|
owner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension UISearchBar {
|
extension UISearchBar {
|
||||||
var searchQueryWithOperators: String {
|
var searchQueryWithOperators: String {
|
||||||
var parts = searchTextField.tokens.compactMap { $0.representedObject as? String }
|
var parts = searchTextField.tokens.compactMap { $0.representedObject as? String }
|
||||||
|
|
|
@ -8,6 +8,13 @@
|
||||||
|
|
||||||
import UIKit
|
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 {
|
class MultiColumnNavigationController: UIViewController {
|
||||||
|
|
||||||
private var isManuallyUpdating = false
|
private var isManuallyUpdating = false
|
||||||
|
@ -99,6 +106,8 @@ class MultiColumnNavigationController: UIViewController {
|
||||||
index = _viewControllers.firstIndex(of: c)
|
index = _viewControllers.firstIndex(of: c)
|
||||||
if index != nil {
|
if index != nil {
|
||||||
break
|
break
|
||||||
|
} else if let targetProviding = c as? MultiColumnNavigationCustomTargetProviding {
|
||||||
|
current = targetProviding.multiColumnNavigationTargetViewController
|
||||||
} else {
|
} else {
|
||||||
current = c.parent
|
current = c.parent
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue