AppNavigator.swift 1.56 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
//
//  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 apps
    }
    
    // MARK: - Initializers
    
    public init() {
        self.tabBarController = UITabBarController()
        
        self.createTabs()
    }
    
    // MARK: - Tab Bar Tabs
    
    private func createTabs() {
        // Create all tabs
        self.createHomeTab()
        self.createAmivApplicationTab()
domenicw's avatar
domenicw committed
45
        self.createSettingsTab()
domenicw's avatar
domenicw committed
46
47
48
49
50
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)
    }
    
    private func createAmivApplicationTab() {
        let app = AmivApplicationsNavigator()
        self.childNavigators.append(app)
    }
    
domenicw's avatar
domenicw committed
63
64
65
66
67
    private func createSettingsTab() {
        let settings = SettingsNavigator()
        self.childNavigators.append(settings)
    }
    
domenicw's avatar
domenicw committed
68
}