forked from slackhq/PanModal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleViewController.swift
125 lines (101 loc) · 3.9 KB
/
SampleViewController.swift
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// SampleViewController.swift
// PanModal
//
// Created by Stephen Sowole on 10/9/18.
// Copyright © 2018 PanModal. All rights reserved.
//
import UIKit
class SampleViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupView()
}
private func setupView() {
title = "PanModal"
navigationController?.navigationBar.titleTextAttributes = [
.font: UIFont(name: "Lato-Bold", size: 17)!
]
tableView.register(UITableViewCell.self, forCellReuseIdentifier: String(describing: UITableViewCell.self))
tableView.tableFooterView = UIView()
tableView.separatorInset = .zero
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60.0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return RowType.allCases.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UITableViewCell.self), for: indexPath)
guard let rowType = RowType(rawValue: indexPath.row) else {
return cell
}
cell.textLabel?.textAlignment = .center
cell.textLabel?.text = rowType.presentable.string
cell.textLabel?.font = UIFont(name: "Lato-Regular", size: 17.0)
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
guard let rowType = RowType(rawValue: indexPath.row) else {
return
}
dismiss(animated: true, completion: nil)
presentPanModal(rowType.presentable.rowVC)
}
}
protocol RowPresentable {
var string: String { get }
var rowVC: UIViewController & PanModalPresentable { get }
}
private extension SampleViewController {
enum RowType: Int, CaseIterable {
case basic
case fullScreen
case alert
case transientAlert
case userGroups
case stacked
case navController
var presentable: RowPresentable {
switch self {
case .basic: return Basic()
case .fullScreen: return FullScreen()
case .alert: return Alert()
case .transientAlert: return TransientAlert()
case .userGroups: return UserGroup()
case .stacked: return Stacked()
case .navController: return Navigation()
}
}
struct Basic: RowPresentable {
let string: String = "Basic"
let rowVC: PanModalPresentable.LayoutType = BasicViewController()
}
struct FullScreen: RowPresentable {
let string: String = "Full Screen"
let rowVC: PanModalPresentable.LayoutType = FullScreenNavController()
}
struct Alert: RowPresentable {
let string: String = "Alert"
let rowVC: PanModalPresentable.LayoutType = AlertViewController()
}
struct TransientAlert: RowPresentable {
let string: String = "Alert (Transient)"
let rowVC: PanModalPresentable.LayoutType = TransientAlertViewController()
}
struct UserGroup: RowPresentable {
let string: String = "User Groups"
let rowVC: PanModalPresentable.LayoutType = UserGroupViewController()
}
struct Navigation: RowPresentable {
let string: String = "User Groups (NavigationController)"
let rowVC: PanModalPresentable.LayoutType = NavigationController()
}
struct Stacked: RowPresentable {
let string: String = "User Groups (Stacked)"
let rowVC: PanModalPresentable.LayoutType = UserGroupStackedViewController()
}
}
}