// // MainTabBarViewController.swift // Tusker // // Created by Shadowfactson 8/21/18. // Copyright © 2018 Shadowfacts. All rights reserved. // import UIKit class MainTabBarViewController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() updateTabs(animated: false) } func updateTabs(animated: Bool) { let currentTabs = Preferences.shared.tabs.filter { $1 >= 0 }.sorted { $1.1 > $0.1 }.map { $0.key } let viewControllers: [UIViewController] = currentTabs.map { (tab) in if tab == .preferences, let preferences = selectedViewController { return preferences } else { return embedInNavigationController(createVC(for: tab)) } } setViewControllers(viewControllers, animated: animated) } func createVC(for tab: Tab) -> UIViewController { switch tab { case .home: return TimelineTableViewController(for: .home) case .federated: return TimelineTableViewController(for: .public(local: false)) case .local: return TimelineTableViewController(for: .public(local: true)) case .myProfile: let myProfile = ProfileTableViewController(accountID: nil) myProfile.title = "My Profile" MastodonController.getOwnAccount { (account) in myProfile.accountID = account.id } return myProfile case .notifications: return embedInNavigationController(NotificationsTableViewController()) case .preferences: return PreferencesTableViewController.create() } } func embedInNavigationController(_ vc: UIViewController) -> UINavigationController { if let vc = vc as? UINavigationController { return vc } else { return UINavigationController(rootViewController: vc) } } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ }