Fix being able to scroll to top while fast account switcher is active

This commit is contained in:
Shadowfacts 2023-05-10 11:41:59 -04:00
parent 3394c2126c
commit dcd1b4ad94
5 changed files with 40 additions and 7 deletions

View File

@ -238,7 +238,7 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate
} }
} }
func createAppUI() -> TuskerRootViewController { func createAppUI() -> AccountSwitchableViewController {
let mastodonController = window!.windowScene!.session.mastodonController! let mastodonController = window!.windowScene!.session.mastodonController!
mastodonController.initialize() mastodonController.initialize()

View File

@ -11,14 +11,18 @@ import ScreenCorners
import UserAccounts import UserAccounts
import ComposeUI import ComposeUI
protocol AccountSwitchableViewController: TuskerRootViewController {
var isFastAccountSwitcherActive: Bool { get }
}
class AccountSwitchingContainerViewController: UIViewController { class AccountSwitchingContainerViewController: UIViewController {
private var currentAccountID: String private var currentAccountID: String
private(set) var root: TuskerRootViewController private(set) var root: AccountSwitchableViewController
private var userActivities: [String: NSUserActivity] = [:] private var userActivities: [String: NSUserActivity] = [:]
init(root: TuskerRootViewController, for account: UserAccountInfo) { init(root: AccountSwitchableViewController, for account: UserAccountInfo) {
self.currentAccountID = account.id self.currentAccountID = account.id
self.root = root self.root = root
@ -35,7 +39,7 @@ class AccountSwitchingContainerViewController: UIViewController {
embedChild(root) 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 let oldRoot = self.root
if direction == .none { if direction == .none {
oldRoot.removeViewAndController() oldRoot.removeViewAndController()
@ -148,9 +152,12 @@ extension AccountSwitchingContainerViewController: TuskerRootViewController {
func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult { func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult {
loadViewIfNeeded() loadViewIfNeeded()
// TODO: check if fast account switcher is being presented? if root.isFastAccountSwitcherActive {
return .stop
} else {
return root.handleStatusBarTapped(xPosition: xPosition) return root.handleStatusBarTapped(xPosition: xPosition)
} }
}
} }
extension AccountSwitchingContainerViewController: BackgroundableViewController { extension AccountSwitchingContainerViewController: BackgroundableViewController {

View File

@ -11,7 +11,7 @@ import Duckable
import ComposeUI import ComposeUI
@available(iOS 16.0, *) @available(iOS 16.0, *)
extension DuckableContainerViewController: TuskerRootViewController { extension DuckableContainerViewController: AccountSwitchableViewController {
func stateRestorationActivity() -> NSUserActivity? { func stateRestorationActivity() -> NSUserActivity? {
var activity = (child as? TuskerRootViewController)?.stateRestorationActivity() var activity = (child as? TuskerRootViewController)?.stateRestorationActivity()
if let compose = duckedViewController as? ComposeHostingController, if let compose = duckedViewController as? ComposeHostingController,
@ -52,4 +52,8 @@ extension DuckableContainerViewController: TuskerRootViewController {
func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult { func handleStatusBarTapped(xPosition: CGFloat) -> StatusBarTapActionResult {
(child as? TuskerRootViewController)?.handleStatusBarTapped(xPosition: xPosition) ?? .continue (child as? TuskerRootViewController)?.handleStatusBarTapped(xPosition: xPosition) ?? .continue
} }
var isFastAccountSwitcherActive: Bool {
(child as? AccountSwitchableViewController)?.isFastAccountSwitcherActive ?? false
}
} }

View File

@ -610,3 +610,15 @@ extension MainSplitViewController: FastAccountSwitcherViewControllerDelegate {
return cellRect.contains(point) 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
}
}
}

View File

@ -363,3 +363,13 @@ extension MainTabBarViewController: BackgroundableViewController {
} }
} }
} }
extension MainTabBarViewController: AccountSwitchableViewController {
var isFastAccountSwitcherActive: Bool {
if let fastAccountSwitcher {
return !fastAccountSwitcher.view.isHidden
} else {
return false
}
}
}