forked from shadowfacts/Tusker
Use tab bar on visionOS
This commit is contained in:
parent
41481f465a
commit
b6232a9f1e
|
@ -253,10 +253,10 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate
|
|||
let mastodonController = window!.windowScene!.session.mastodonController!
|
||||
mastodonController.initialize()
|
||||
|
||||
let split = MainSplitViewController(mastodonController: mastodonController)
|
||||
#if !canImport(Duckable)
|
||||
return split
|
||||
#if os(visionOS)
|
||||
return MainTabBarViewController(mastodonController: mastodonController)
|
||||
#else
|
||||
let split = MainSplitViewController(mastodonController: mastodonController)
|
||||
if UIDevice.current.userInterfaceIdiom == .phone,
|
||||
#available(iOS 16.0, *) {
|
||||
// TODO: maybe the duckable container should be outside the account switching container
|
||||
|
|
|
@ -15,9 +15,11 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|||
|
||||
private var composePlaceholder: UIViewController!
|
||||
|
||||
#if !os(visionOS)
|
||||
private var fastAccountSwitcher: FastAccountSwitcherViewController!
|
||||
private var fastSwitcherIndicator: FastAccountSwitcherIndicatorView!
|
||||
private var fastSwitcherConstraints: [NSLayoutConstraint] = []
|
||||
#endif
|
||||
|
||||
var selectedTab: Tab {
|
||||
return Tab(rawValue: selectedIndex)!
|
||||
|
@ -60,6 +62,7 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|||
embedInNavigationController(Tab.myProfile.createViewController(mastodonController)),
|
||||
]
|
||||
|
||||
#if !os(visionOS)
|
||||
fastAccountSwitcher = FastAccountSwitcherViewController()
|
||||
fastAccountSwitcher.delegate = self
|
||||
fastAccountSwitcher.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
@ -74,16 +77,13 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|||
fastSwitcherIndicator.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(fastSwitcherIndicator)
|
||||
}
|
||||
#endif
|
||||
|
||||
tabBar.isSpringLoaded = true
|
||||
|
||||
#if os(visionOS)
|
||||
registerForTraitChanges([UITraitHorizontalSizeClass.self]) { (self: Self, previousTraitCollection) in
|
||||
self.repositionFastSwitcherIndicator()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Fast account switcher is not supported on visionOS
|
||||
#if !os(visionOS)
|
||||
override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
|
||||
|
@ -93,7 +93,6 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|||
repositionFastSwitcherIndicator()
|
||||
}
|
||||
|
||||
#if !os(visionOS)
|
||||
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||
super.traitCollectionDidChange(previousTraitCollection)
|
||||
|
||||
|
@ -126,6 +125,7 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
#if !os(visionOS)
|
||||
private func repositionFastSwitcherIndicator() {
|
||||
guard let myProfileButton = findMyProfileTabBarButton() else {
|
||||
return
|
||||
|
@ -146,6 +146,7 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|||
}
|
||||
NSLayoutConstraint.activate(fastSwitcherConstraints)
|
||||
}
|
||||
#endif
|
||||
|
||||
private func findMyProfileTabBarButton() -> UIView? {
|
||||
let tabBarButtons = tabBar.subviews.filter { String(describing: type(of: $0)).lowercased().contains("button") }
|
||||
|
@ -157,9 +158,11 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|||
return myProfileButton
|
||||
}
|
||||
|
||||
#if !os(visionOS)
|
||||
@objc private func tabBarTapped(_ recognizer: UITapGestureRecognizer) {
|
||||
fastAccountSwitcher.hide()
|
||||
}
|
||||
#endif
|
||||
|
||||
@objc func handleComposeKeyCommand() {
|
||||
compose(editing: nil)
|
||||
|
@ -235,6 +238,7 @@ extension MainTabBarViewController {
|
|||
}
|
||||
}
|
||||
|
||||
#if !os(visionOS)
|
||||
extension MainTabBarViewController: FastAccountSwitcherViewControllerDelegate {
|
||||
func fastAccountSwitcherAddToViewHierarchy(_ fastAccountSwitcher: FastAccountSwitcherViewController) {
|
||||
view.addSubview(fastAccountSwitcher.view)
|
||||
|
@ -256,6 +260,7 @@ extension MainTabBarViewController: FastAccountSwitcherViewControllerDelegate {
|
|||
return myProfileButton.bounds.contains(locationInButton)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extension MainTabBarViewController: TuskerNavigationDelegate {
|
||||
var apiController: MastodonController! { mastodonController }
|
||||
|
@ -357,10 +362,14 @@ extension MainTabBarViewController: BackgroundableViewController {
|
|||
|
||||
extension MainTabBarViewController: AccountSwitchableViewController {
|
||||
var isFastAccountSwitcherActive: Bool {
|
||||
#if os(visionOS)
|
||||
return false
|
||||
#else
|
||||
if let fastAccountSwitcher {
|
||||
return !fastAccountSwitcher.view.isHidden
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue