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