AppNavigator.swift 2.07 KB
Newer Older
domenicw's avatar
domenicw committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
//  AppNavigator.swift
//  Amiv
//
//  Created by Domenic Wüthrich on 18.09.18.
//  Copyright © 2018 Amiv an der ETH. All rights reserved.
//

import Foundation
import UIKit

public class AppNavigator: Navigator {
    
    // MARK: - Variables
    
    private var childNavigators: [Navigator] = []
    
    public var rootViewController: UIViewController {
        return tabBarController
    }
    
    private var tabBarController: UITabBarController
    
    // MARK: - Tabs
    
    private enum Tab: Int {
domenicw's avatar
domenicw committed
27
        //case home
28
29
        case events
        case jobs
domenicw's avatar
domenicw committed
30
        case apps
domenicw's avatar
domenicw committed
31
        case settings
domenicw's avatar
domenicw committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    }
    
    // MARK: - Initializers
    
    public init() {
        self.tabBarController = UITabBarController()
        
        self.createTabs()
    }
    
    // MARK: - Tab Bar Tabs
    
    private func createTabs() {
        // Create all tabs
domenicw's avatar
domenicw committed
46
        //self.createHomeTab()
47
48
        self.createEventsTab()
        self.createJobsTab()
domenicw's avatar
domenicw committed
49
        self.createAmivApplicationTab()
domenicw's avatar
domenicw committed
50
        self.createSettingsTab()
domenicw's avatar
domenicw committed
51
52
53
        
        // Make tabBarController ready
        self.tabBarController.viewControllers = self.childNavigators.map({ $0.rootViewController })
domenicw's avatar
domenicw committed
54
        self.tabBarController.selectedIndex = Tab.events.rawValue
domenicw's avatar
domenicw committed
55
56
57
58
59
60
61
62
        self.tabBarController.tabBar.tintColor = .amivRed
    }
    
    private func createHomeTab() {
        let home = HomeNavigator()
        self.childNavigators.append(home)
    }
    
63
64
65
66
67
68
69
70
71
72
    private func createEventsTab() {
        let events = EventsNavigator()
        self.childNavigators.append(events)
    }
    
    private func createJobsTab() {
        let jobs = JobsNavigator()
        self.childNavigators.append(jobs)
    }
    
domenicw's avatar
domenicw committed
73
    private func createAmivApplicationTab() {
domenicw's avatar
domenicw committed
74
        let app = AmivMicroAppsNavigator()
domenicw's avatar
domenicw committed
75
76
77
        self.childNavigators.append(app)
    }
    
domenicw's avatar
domenicw committed
78
79
    private func createSettingsTab() {
        let settings = SettingsNavigator()
domenicw's avatar
domenicw committed
80
        settings.rootViewController.tabBarItem = UITabBarItem(title: "Settings", image: UIImage(named: "settings"), tag: Tab.settings.rawValue)
domenicw's avatar
domenicw committed
81
82
83
        self.childNavigators.append(settings)
    }
    
domenicw's avatar
domenicw committed
84
}