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