Tusker/Tusker/Screens/Main/MainTabBarViewController.swift

47 lines
1.5 KiB
Swift

//
// MainTabBarViewController.swift
// Tusker
//
// Created by Shadowfactson 8/21/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
lazy var router = AppRouter(root: self)
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
viewControllers = [
embedInNavigationController(TimelineTableViewController(for: .home, router: router)),
embedInNavigationController(NotificationsTableViewController(router: router)),
ComposeViewController(router: router),
embedInNavigationController(TimelineTableViewController(for: .public(local: false), router: router)),
embedInNavigationController(MyProfileTableViewController(router: router)),
]
}
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 {
let compose = embedInNavigationController(ComposeViewController(router: router))
tabBarController.present(compose, animated: true)
return false
}
return true
}
}