forked from shadowfacts/Tusker
Shadowfacts
65d57df949
Allows people to move forward in the navigation stack after popping (making popping a non-destructive action).
96 lines
2.8 KiB
Swift
96 lines
2.8 KiB
Swift
//
|
|
// MainTabBarViewController.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 8/21/18.
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|
|
|
weak var mastodonController: MastodonController!
|
|
|
|
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
|
if UIDevice.current.userInterfaceIdiom == .phone {
|
|
return .portrait
|
|
} else {
|
|
return .all
|
|
}
|
|
}
|
|
|
|
init(mastodonController: MastodonController) {
|
|
self.mastodonController = mastodonController
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
self.delegate = self
|
|
|
|
viewControllers = [
|
|
embedInNavigationController(TimelinesPageViewController(mastodonController: mastodonController)),
|
|
embedInNavigationController(NotificationsPageViewController(mastodonController: mastodonController)),
|
|
ComposeViewController(mastodonController: mastodonController),
|
|
embedInNavigationController(ExploreViewController(mastodonController: mastodonController)),
|
|
embedInNavigationController(MyProfileTableViewController(mastodonController: mastodonController)),
|
|
]
|
|
}
|
|
|
|
func embedInNavigationController(_ vc: UIViewController) -> UINavigationController {
|
|
if let vc = vc as? UINavigationController {
|
|
return vc
|
|
} else {
|
|
return EnhancedNavigationViewController(rootViewController: vc)
|
|
}
|
|
}
|
|
|
|
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
|
|
if viewController is ComposeViewController {
|
|
presentCompose()
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func presentCompose() {
|
|
let compose = ComposeViewController(mastodonController: mastodonController)
|
|
let navigationController = embedInNavigationController(compose)
|
|
navigationController.presentationController?.delegate = compose
|
|
present(navigationController, animated: true)
|
|
}
|
|
}
|
|
|
|
extension MainTabBarViewController {
|
|
enum Tab: Int {
|
|
case timelines
|
|
case notifications
|
|
case compose
|
|
case explore
|
|
case myProfile
|
|
}
|
|
|
|
func select(tab: Tab) {
|
|
if tab == .compose {
|
|
presentCompose()
|
|
} else {
|
|
selectedIndex = tab.rawValue
|
|
}
|
|
}
|
|
|
|
func getTabController(tab: Tab) -> UIViewController? {
|
|
if tab == .compose {
|
|
return nil
|
|
} else {
|
|
return viewControllers![tab.rawValue]
|
|
}
|
|
}
|
|
}
|