Fix assorted issues collapsing/expanding split VC

This commit is contained in:
Shadowfacts 2023-05-09 16:42:16 -04:00
parent 9fc4aa8a40
commit ee651ae96a
2 changed files with 24 additions and 12 deletions

View File

@ -225,6 +225,7 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
// so that explore items aren't shown multiple times. // so that explore items aren't shown multiple times.
let exploreNav = tabBarViewController.viewController(for: .explore) as! UINavigationController let exploreNav = tabBarViewController.viewController(for: .explore) as! UINavigationController
// make sure there's a root ExploreViewController
let explore: ExploreViewController let explore: ExploreViewController
if let existing = exploreNav.viewControllers.first as? ExploreViewController { if let existing = exploreNav.viewControllers.first as? ExploreViewController {
explore = existing explore = existing
@ -238,6 +239,7 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
explore.loadViewIfNeeded() explore.loadViewIfNeeded()
let search = secondaryNavController.viewControllers.first as! InlineTrendsViewController let search = secondaryNavController.viewControllers.first as! InlineTrendsViewController
if search.searchController.isActive {
// Copy the search query from the search VC to the Explore VC's search controller. // Copy the search query from the search VC to the Explore VC's search controller.
let query = search.searchController.searchBar.text ?? "" let query = search.searchController.searchBar.text ?? ""
explore.searchController.searchBar.text = query explore.searchController.searchBar.text = query
@ -246,6 +248,14 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
explore.searchControllerStatusOnAppearance = !query.isEmpty explore.searchControllerStatusOnAppearance = !query.isEmpty
// Copy the results from the search VC's results controller to avoid the delay introduced by an extra network request // Copy the results from the search VC's results controller to avoid the delay introduced by an extra network request
explore.resultsController.loadResults(from: search.resultsController) explore.resultsController.loadResults(from: search.resultsController)
} else {
// if there is more than just the InlineTrendsVC, and the search VC is not active,
// then the user selected something from the trends screen
if secondaryNavController.viewControllers.count >= 2 {
// make sure there's a corresponding trends VC in the collapsed nav that they can go back to
exploreNav.pushViewController(TrendsViewController(mastodonController: mastodonController), animated: false)
}
}
// Transfer the navigation stack, dropping the search VC, to keep anything the user has opened // Transfer the navigation stack, dropping the search VC, to keep anything the user has opened
transferNavigationStack(from: .explore, to: exploreNav, dropFirst: true, append: true) transferNavigationStack(from: .explore, to: exploreNav, dropFirst: true, append: true)
@ -329,14 +339,16 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
exploreItem = .favorites exploreItem = .favorites
case let listVC as ListTimelineViewController: case let listVC as ListTimelineViewController:
exploreItem = .list(listVC.list) exploreItem = .list(listVC.list)
case let hashtagVC as HashtagTimelineViewController: case let hashtagVC as HashtagTimelineViewController where hashtagVC.isHashtagSaved:
exploreItem = .savedHashtag(hashtagVC.hashtag) exploreItem = .savedHashtag(hashtagVC.hashtag)
case let instanceVC as InstanceTimelineViewController: case let instanceVC as InstanceTimelineViewController:
exploreItem = .savedInstance(instanceVC.instanceURL) exploreItem = .savedInstance(instanceVC.instanceURL)
case is TrendingStatusesViewController, is TrendingHashtagsViewController, is TrendingLinksViewController: case is TrendsViewController:
exploreItem = .explore exploreItem = .explore
// these three VCs are part of the root SearchViewController, so we don't need to transfer them // skip transferring the ExploreViewController and TrendsViewController
skipFirst = 2 skipFirst = 2
// prepend the InlineTrendsViewController
toPrepend = getOrCreateNavigationStack(item: .explore).first!
default: default:
// transfer the navigation stack prepending, the existing explore VC // transfer the navigation stack prepending, the existing explore VC
// if there was other stuff on the explore stack, it will get discarded // if there was other stuff on the explore stack, it will get discarded

View File

@ -15,7 +15,7 @@ class HashtagTimelineViewController: TimelineViewController {
var toggleSaveButton: UIBarButtonItem! var toggleSaveButton: UIBarButtonItem!
private var isHashtagSaved: Bool { var isHashtagSaved: Bool {
let req = SavedHashtag.fetchRequest(name: hashtag.name, account: mastodonController.accountInfo!) let req = SavedHashtag.fetchRequest(name: hashtag.name, account: mastodonController.accountInfo!)
return mastodonController.persistentContainer.viewContext.objectExists(for: req) return mastodonController.persistentContainer.viewContext.objectExists(for: req)
} }