84 lines
2.3 KiB
Swift
84 lines
2.3 KiB
Swift
//
|
|
// MainTabBarViewController.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 8/21/18.
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
|
|
|
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
|
if UIDevice.current.userInterfaceIdiom == .phone {
|
|
return .portrait
|
|
} else {
|
|
return .all
|
|
}
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
self.delegate = self
|
|
|
|
viewControllers = [
|
|
embedInNavigationController(TimelinesPageViewController()),
|
|
embedInNavigationController(NotificationsPageViewController()),
|
|
ComposeViewController(),
|
|
embedInNavigationController(ExploreViewController()),
|
|
embedInNavigationController(MyProfileTableViewController()),
|
|
]
|
|
}
|
|
|
|
func embedInNavigationController(_ vc: UIViewController) -> UINavigationController {
|
|
if let vc = vc as? UINavigationController {
|
|
return vc
|
|
} else {
|
|
return UINavigationController(rootViewController: vc)
|
|
}
|
|
}
|
|
|
|
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
|
|
if viewController is ComposeViewController {
|
|
presentCompose()
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func presentCompose() {
|
|
let compose = ComposeViewController()
|
|
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]
|
|
}
|
|
}
|
|
}
|