|
| 1 | +// |
| 2 | +// TabViewController.swift |
| 3 | +// BrickHack-Mobile |
| 4 | +// |
| 5 | +// Created by Peter Kos on 2/3/20. |
| 6 | +// Copyright © 2020 codeRIT. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import UIKit |
| 10 | +import Pageboy |
| 11 | +import Tabman |
| 12 | + |
| 13 | + |
| 14 | +class TabViewController: TabmanViewController, PageboyViewControllerDataSource, TMBarDataSource { |
| 15 | + |
| 16 | + var currentUser: User! |
| 17 | + private var viewControllers = [UIViewController]() |
| 18 | + |
| 19 | + override func viewDidLoad() { |
| 20 | + super.viewDidLoad() |
| 21 | + |
| 22 | + // Set PageboyViewControllerDataSource |
| 23 | + dataSource = self |
| 24 | + |
| 25 | + // Instantiate our view controller from the storyboard |
| 26 | + let storyboard = UIStoryboard(name: "Main", bundle: nil) |
| 27 | + |
| 28 | + // Even though delegate methods are polymorphic, |
| 29 | + // we need cast to properly set the user data. |
| 30 | + let eventsVC = storyboard.instantiateViewController(withIdentifier: "eventsVC") as! EventsViewController |
| 31 | + let resourcesVC = storyboard.instantiateViewController(withIdentifier: "resourcesVC") as! ResourcesViewController |
| 32 | + |
| 33 | + // Pass our user object forward |
| 34 | + eventsVC.currentUser = self.currentUser |
| 35 | + resourcesVC.currentUser = self.currentUser |
| 36 | + |
| 37 | + self.viewControllers.append(eventsVC) |
| 38 | + self.viewControllers.append(resourcesVC) |
| 39 | + |
| 40 | + self.reloadData() |
| 41 | + |
| 42 | + // Create bar |
| 43 | + // @TODO: Dark Mode |
| 44 | + let bar = TMBar.LineBar() |
| 45 | + bar.layout.contentInset.top = 30.0 |
| 46 | + bar.layout.transitionStyle = .progressive |
| 47 | + bar.backgroundColor = .white |
| 48 | + bar.indicator.cornerStyle = .rounded |
| 49 | + if self.traitCollection.userInterfaceStyle == .dark { |
| 50 | + bar.indicator.tintColor = UIColor.init(named: "quadColor") |
| 51 | + } else { |
| 52 | + bar.indicator.tintColor = UIColor.init(named: "tertiaryColor") |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | + // Add to view |
| 57 | + self.addBar(bar, dataSource: self, at: .top) |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + // MARK: PageboyViewControllerSource |
| 63 | + |
| 64 | + func numberOfViewControllers(in pageboyViewController: PageboyViewController) -> Int { |
| 65 | + return viewControllers.count |
| 66 | + } |
| 67 | + |
| 68 | + func viewController(for pageboyViewController: PageboyViewController, at index: PageboyViewController.PageIndex) -> UIViewController? { |
| 69 | + return viewControllers[index] |
| 70 | + } |
| 71 | + |
| 72 | + func defaultPage(for pageboyViewController: PageboyViewController) -> PageboyViewController.Page? { |
| 73 | + return .first |
| 74 | + } |
| 75 | + |
| 76 | + // MARK: TMBarDataSource |
| 77 | + func barItem(for bar: TMBar, at index: Int) -> TMBarItemable { |
| 78 | + print("indexed at \(index)") |
| 79 | + if index == 0 { |
| 80 | + return TMBarItem(title: "Schedule") |
| 81 | + } else if index == 2 { |
| 82 | + return TMBarItem(title: "Resources") |
| 83 | + } else { |
| 84 | + return TMBarItem(title: "Unknown") |
| 85 | + } |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | + |
0 commit comments