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
27
//
//  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 {
        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
46
    }
    
    // MARK: - Initializers
    
    public init() {
        self.tabBarController = UITabBarController()
        
        self.createTabs()
    }
    
    // MARK: - Tab Bar Tabs
    
    private func createTabs() {
        // Create all tabs
        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
54
55
56
57
58
59
60
61
62
        
        // Make tabBarController ready
        self.tabBarController.viewControllers = self.childNavigators.map({ $0.rootViewController })
        self.tabBarController.selectedIndex = Tab.home.rawValue
        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
74
75
76
77
    private func createAmivApplicationTab() {
        let app = AmivApplicationsNavigator()
        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
}