2018-08-21 21:17:25 +00:00
|
|
|
//
|
|
|
|
// MainTabBarViewController.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
2019-02-08 18:41:19 +00:00
|
|
|
// Created by Shadowfacts on 8/21/18.
|
2018-08-21 21:17:25 +00:00
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
2019-01-05 17:59:55 +00:00
|
|
|
class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
2020-01-05 20:25:07 +00:00
|
|
|
|
|
|
|
let mastodonController: MastodonController
|
2018-08-21 21:17:25 +00:00
|
|
|
|
2020-01-08 03:19:38 +00:00
|
|
|
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
|
|
|
if UIDevice.current.userInterfaceIdiom == .phone {
|
|
|
|
return .portrait
|
|
|
|
} else {
|
|
|
|
return .all
|
|
|
|
}
|
|
|
|
}
|
2020-01-05 20:25:07 +00:00
|
|
|
|
|
|
|
init(mastodonController: MastodonController) {
|
|
|
|
self.mastodonController = mastodonController
|
|
|
|
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
2020-01-18 23:56:36 +00:00
|
|
|
}
|
2020-01-05 20:25:07 +00:00
|
|
|
|
2018-08-21 21:17:25 +00:00
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2019-01-05 17:59:55 +00:00
|
|
|
self.delegate = self
|
|
|
|
|
|
|
|
viewControllers = [
|
2020-01-05 20:25:07 +00:00
|
|
|
embedInNavigationController(TimelinesPageViewController(mastodonController: mastodonController)),
|
|
|
|
embedInNavigationController(NotificationsPageViewController(mastodonController: mastodonController)),
|
|
|
|
ComposeViewController(mastodonController: mastodonController),
|
|
|
|
embedInNavigationController(ExploreViewController(mastodonController: mastodonController)),
|
|
|
|
embedInNavigationController(MyProfileTableViewController(mastodonController: mastodonController)),
|
2019-01-05 17:59:55 +00:00
|
|
|
]
|
2018-08-21 21:17:25 +00:00
|
|
|
}
|
|
|
|
|
2018-10-06 14:38:36 +00:00
|
|
|
func embedInNavigationController(_ vc: UIViewController) -> UINavigationController {
|
|
|
|
if let vc = vc as? UINavigationController {
|
|
|
|
return vc
|
|
|
|
} else {
|
|
|
|
return UINavigationController(rootViewController: vc)
|
|
|
|
}
|
2018-10-01 01:28:22 +00:00
|
|
|
}
|
2018-08-31 02:30:19 +00:00
|
|
|
|
2019-01-05 17:59:55 +00:00
|
|
|
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
|
|
|
|
if viewController is ComposeViewController {
|
2019-09-16 01:00:57 +00:00
|
|
|
presentCompose()
|
2019-01-05 17:59:55 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-09-16 01:00:57 +00:00
|
|
|
func presentCompose() {
|
2020-01-05 20:25:07 +00:00
|
|
|
let compose = ComposeViewController(mastodonController: mastodonController)
|
2019-09-16 01:00:57 +00:00
|
|
|
let navigationController = embedInNavigationController(compose)
|
|
|
|
navigationController.presentationController?.delegate = compose
|
|
|
|
present(navigationController, animated: true)
|
|
|
|
}
|
2019-09-16 01:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension MainTabBarViewController {
|
|
|
|
enum Tab: Int {
|
|
|
|
case timelines
|
|
|
|
case notifications
|
|
|
|
case compose
|
2019-12-17 05:22:25 +00:00
|
|
|
case explore
|
2019-09-16 01:15:32 +00:00
|
|
|
case myProfile
|
|
|
|
}
|
2019-09-16 01:00:57 +00:00
|
|
|
|
|
|
|
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]
|
|
|
|
}
|
|
|
|
}
|
2018-08-21 21:17:25 +00:00
|
|
|
}
|