From dcd1b4ad94f355dc42a5f386baec0a3667d83483 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 10 May 2023 11:41:59 -0400 Subject: [PATCH] Fix being able to scroll to top while fast account switcher is active --- Tusker/Scenes/MainSceneDelegate.swift | 2 +- ...ccountSwitchingContainerViewController.swift | 17 ++++++++++++----- Tusker/Screens/Main/Duckable+Root.swift | 6 +++++- .../Screens/Main/MainSplitViewController.swift | 12 ++++++++++++ .../Screens/Main/MainTabBarViewController.swift | 10 ++++++++++ 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Tusker/Scenes/MainSceneDelegate.swift b/Tusker/Scenes/MainSceneDelegate.swift index 6d8af805..4e657dad 100644 --- a/Tusker/Scenes/MainSceneDelegate.swift +++ b/Tusker/Scenes/MainSceneDelegate.swift @@ -238,7 +238,7 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate } } - func createAppUI() -> TuskerRootViewController { + func createAppUI() -> AccountSwitchableViewController { let mastodonController = window!.windowScene!.session.mastodonController! mastodonController.initialize() diff --git a/Tusker/Screens/Main/AccountSwitchingContainerViewController.swift b/Tusker/Screens/Main/AccountSwitchingContainerViewController.swift index 1b325867..e76781c3 100644 --- a/Tusker/Screens/Main/AccountSwitchingContainerViewController.swift +++ b/Tusker/Screens/Main/AccountSwitchingContainerViewController.swift @@ -11,14 +11,18 @@ import ScreenCorners import UserAccounts import ComposeUI +protocol AccountSwitchableViewController: TuskerRootViewController { + var isFastAccountSwitcherActive: Bool { get } +} + class AccountSwitchingContainerViewController: UIViewController { private var currentAccountID: String - private(set) var root: TuskerRootViewController + private(set) var root: AccountSwitchableViewController private var userActivities: [String: NSUserActivity] = [:] - init(root: TuskerRootViewController, for account: UserAccountInfo) { + init(root: AccountSwitchableViewController, for account: UserAccountInfo) { self.currentAccountID = account.id self.root = root @@ -35,7 +39,7 @@ class AccountSwitchingContainerViewController: UIViewController { embedChild(root) } - func setRoot(_ newRoot: TuskerRootViewController, for account: UserAccountInfo, animating direction: AnimationDirection) { + func setRoot(_ newRoot: AccountSwitchableViewController, for account: UserAccountInfo, animating direction: AnimationDirection) { let oldRoot = self.root if direction == .none { oldRoot.removeViewAndController() @@ -148,8 +152,11 @@ extension AccountSwitchingContainerViewController: TuskerRootViewController { func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult { loadViewIfNeeded() - // TODO: check if fast account switcher is being presented? - return root.handleStatusBarTapped(xPosition: xPosition) + if root.isFastAccountSwitcherActive { + return .stop + } else { + return root.handleStatusBarTapped(xPosition: xPosition) + } } } diff --git a/Tusker/Screens/Main/Duckable+Root.swift b/Tusker/Screens/Main/Duckable+Root.swift index b349f104..77c8d62b 100644 --- a/Tusker/Screens/Main/Duckable+Root.swift +++ b/Tusker/Screens/Main/Duckable+Root.swift @@ -11,7 +11,7 @@ import Duckable import ComposeUI @available(iOS 16.0, *) -extension DuckableContainerViewController: TuskerRootViewController { +extension DuckableContainerViewController: AccountSwitchableViewController { func stateRestorationActivity() -> NSUserActivity? { var activity = (child as? TuskerRootViewController)?.stateRestorationActivity() if let compose = duckedViewController as? ComposeHostingController, @@ -52,4 +52,8 @@ extension DuckableContainerViewController: TuskerRootViewController { func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult { (child as? TuskerRootViewController)?.handleStatusBarTapped(xPosition: xPosition) ?? .continue } + + var isFastAccountSwitcherActive: Bool { + (child as? AccountSwitchableViewController)?.isFastAccountSwitcherActive ?? false + } } diff --git a/Tusker/Screens/Main/MainSplitViewController.swift b/Tusker/Screens/Main/MainSplitViewController.swift index af2d2599..8d7e0876 100644 --- a/Tusker/Screens/Main/MainSplitViewController.swift +++ b/Tusker/Screens/Main/MainSplitViewController.swift @@ -610,3 +610,15 @@ extension MainSplitViewController: FastAccountSwitcherViewControllerDelegate { return cellRect.contains(point) } } + +extension MainSplitViewController: AccountSwitchableViewController { + var isFastAccountSwitcherActive: Bool { + if isCollapsed { + return tabBarViewController.isFastAccountSwitcherActive + } else if let fastAccountSwitcher { + return !fastAccountSwitcher.view.isHidden + } else { + return false + } + } +} diff --git a/Tusker/Screens/Main/MainTabBarViewController.swift b/Tusker/Screens/Main/MainTabBarViewController.swift index 6fb73312..a2a0adf1 100644 --- a/Tusker/Screens/Main/MainTabBarViewController.swift +++ b/Tusker/Screens/Main/MainTabBarViewController.swift @@ -363,3 +363,13 @@ extension MainTabBarViewController: BackgroundableViewController { } } } + +extension MainTabBarViewController: AccountSwitchableViewController { + var isFastAccountSwitcherActive: Bool { + if let fastAccountSwitcher { + return !fastAccountSwitcher.view.isHidden + } else { + return false + } + } +}