From ee651ae96a193f1307eaef4397a921a75a571bbf Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 9 May 2023 16:42:16 -0400 Subject: [PATCH] Fix assorted issues collapsing/expanding split VC --- .../Main/MainSplitViewController.swift | 34 +++++++++++++------ .../HashtagTimelineViewController.swift | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Tusker/Screens/Main/MainSplitViewController.swift b/Tusker/Screens/Main/MainSplitViewController.swift index e580bd53..af2d2599 100644 --- a/Tusker/Screens/Main/MainSplitViewController.swift +++ b/Tusker/Screens/Main/MainSplitViewController.swift @@ -225,6 +225,7 @@ extension MainSplitViewController: UISplitViewControllerDelegate { // so that explore items aren't shown multiple times. let exploreNav = tabBarViewController.viewController(for: .explore) as! UINavigationController + // make sure there's a root ExploreViewController let explore: ExploreViewController if let existing = exploreNav.viewControllers.first as? ExploreViewController { explore = existing @@ -238,14 +239,23 @@ extension MainSplitViewController: UISplitViewControllerDelegate { explore.loadViewIfNeeded() let search = secondaryNavController.viewControllers.first as! InlineTrendsViewController - // Copy the search query from the search VC to the Explore VC's search controller. - let query = search.searchController.searchBar.text ?? "" - explore.searchController.searchBar.text = query - // Instruct the explore controller to show its search controller immediately upon its first appearance. - // explore.searchController.isActive can't be set directly, see FB7814561 - explore.searchControllerStatusOnAppearance = !query.isEmpty - // 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) + if search.searchController.isActive { + // Copy the search query from the search VC to the Explore VC's search controller. + let query = search.searchController.searchBar.text ?? "" + explore.searchController.searchBar.text = query + // Instruct the explore controller to show its search controller immediately upon its first appearance. + // explore.searchController.isActive can't be set directly, see FB7814561 + explore.searchControllerStatusOnAppearance = !query.isEmpty + // 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) + } 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 transferNavigationStack(from: .explore, to: exploreNav, dropFirst: true, append: true) @@ -329,14 +339,16 @@ extension MainSplitViewController: UISplitViewControllerDelegate { exploreItem = .favorites case let listVC as ListTimelineViewController: exploreItem = .list(listVC.list) - case let hashtagVC as HashtagTimelineViewController: + case let hashtagVC as HashtagTimelineViewController where hashtagVC.isHashtagSaved: exploreItem = .savedHashtag(hashtagVC.hashtag) case let instanceVC as InstanceTimelineViewController: exploreItem = .savedInstance(instanceVC.instanceURL) - case is TrendingStatusesViewController, is TrendingHashtagsViewController, is TrendingLinksViewController: + case is TrendsViewController: 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 + // prepend the InlineTrendsViewController + toPrepend = getOrCreateNavigationStack(item: .explore).first! default: // transfer the navigation stack prepending, the existing explore VC // if there was other stuff on the explore stack, it will get discarded diff --git a/Tusker/Screens/Timeline/HashtagTimelineViewController.swift b/Tusker/Screens/Timeline/HashtagTimelineViewController.swift index 9c404db8..e0b294d1 100644 --- a/Tusker/Screens/Timeline/HashtagTimelineViewController.swift +++ b/Tusker/Screens/Timeline/HashtagTimelineViewController.swift @@ -15,7 +15,7 @@ class HashtagTimelineViewController: TimelineViewController { var toggleSaveButton: UIBarButtonItem! - private var isHashtagSaved: Bool { + var isHashtagSaved: Bool { let req = SavedHashtag.fetchRequest(name: hashtag.name, account: mastodonController.accountInfo!) return mastodonController.persistentContainer.viewContext.objectExists(for: req) }