From f5704e561b8cb15b4e4afae6296c921b3442230f Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 1 Apr 2024 10:35:54 -0400 Subject: [PATCH] Support tapping selected sidebar item to scroll to top --- Tusker/Screens/Main/MainSidebarViewController.swift | 5 ++++- Tusker/Screens/Main/MainSplitViewController.swift | 4 ++++ Tusker/Screens/Utilities/SplitNavigationController.swift | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Main/MainSidebarViewController.swift b/Tusker/Screens/Main/MainSidebarViewController.swift index 970e0c12..47817ffc 100644 --- a/Tusker/Screens/Main/MainSidebarViewController.swift +++ b/Tusker/Screens/Main/MainSidebarViewController.swift @@ -15,6 +15,7 @@ protocol MainSidebarViewControllerDelegate: AnyObject { func sidebarRequestPresentCompose(_ sidebarViewController: MainSidebarViewController) func sidebar(_ sidebarViewController: MainSidebarViewController, didSelectItem item: MainSidebarViewController.Item) func sidebar(_ sidebarViewController: MainSidebarViewController, showViewController viewController: UIViewController) + func sidebar(_ sidebarViewController: MainSidebarViewController, scrollToTopFor item: MainSidebarViewController.Item) } class MainSidebarViewController: UIViewController { @@ -451,7 +452,9 @@ extension MainSidebarViewController: UICollectionViewDelegate { return } itemLastSelectedTimestamps[item] = Date() - if [MainSidebarViewController.Item.tab(.compose), .addList, .addSavedHashtag, .addSavedInstance].contains(item) { + if previouslySelectedItem == item { + sidebarDelegate?.sidebar(self, scrollToTopFor: item) + } else if [MainSidebarViewController.Item.tab(.compose), .addList, .addSavedHashtag, .addSavedInstance].contains(item) { if let previous = previouslySelectedItem, let indexPath = dataSource.indexPath(for: previous) { collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredVertically) } diff --git a/Tusker/Screens/Main/MainSplitViewController.swift b/Tusker/Screens/Main/MainSplitViewController.swift index 806bc4a6..7b021e77 100644 --- a/Tusker/Screens/Main/MainSplitViewController.swift +++ b/Tusker/Screens/Main/MainSplitViewController.swift @@ -478,6 +478,10 @@ extension MainSplitViewController: MainSidebarViewControllerDelegate { } secondaryNavController.viewControllers = [viewController] } + + func sidebar(_ sidebarViewController: MainSidebarViewController, scrollToTopFor item: MainSidebarViewController.Item) { + (secondaryNavController as? TabBarScrollableViewController)?.tabBarScrollToTop() + } } fileprivate extension MainSidebarViewController.Item { diff --git a/Tusker/Screens/Utilities/SplitNavigationController.swift b/Tusker/Screens/Utilities/SplitNavigationController.swift index 0b179737..2e0cf2bb 100644 --- a/Tusker/Screens/Utilities/SplitNavigationController.swift +++ b/Tusker/Screens/Utilities/SplitNavigationController.swift @@ -258,6 +258,12 @@ class SplitNavigationController: UIViewController { } } +extension SplitNavigationController: TabBarScrollableViewController { + func tabBarScrollToTop() { + (viewControllers.last as? TabBarScrollableViewController)?.tabBarScrollToTop() + } +} + extension SplitNavigationController: StatusBarTappableViewController { func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult { let vcs = viewControllers