-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path___FILEBASENAME___Router.swift
executable file
·71 lines (52 loc) · 1.79 KB
/
___FILEBASENAME___Router.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
//___FILEHEADER___
import SwiftUI
struct ___VARIABLE_sceneName___Router: RouterModifierProtocol {
// If you don't need Alerts, you can use `RouterDefaultAlert`. Example: RouterEvents<SomeRouterScreenType, RouterDefaultAlert>
// If you do not need to go to other screens, then use `RouterEmptyScreen`. Example: RouterEvents<RouterEmptyScreen, SomeRouterAlertType>
typealias RouterEventsType = RouterEvents<___VARIABLE_sceneName___ScreenType, ___VARIABLE_sceneName___AlertType>
let routerEvents: RouterEventsType
weak var delegate: ___VARIABLE_sceneName___RouterDelegate?
}
// MARK: - Screens
enum ___VARIABLE_sceneName___ScreenType: RouterScreenProtocol {
case sameScreen
}
extension ___VARIABLE_sceneName___Router {
func getScreenPresentationType(for type: ___VARIABLE_sceneName___ScreenType) -> RouterScreenPresentationType {
switch type {
case .sameScreen:
return .navigationLink
}
}
@ViewBuilder
func getScreen(for type: ___VARIABLE_sceneName___ScreenType) -> some View {
switch type {
case .sameScreen:
Text("Same Screen")
}
}
func onScreenDismiss(type: ___VARIABLE_sceneName___ScreenType) {
delegate?.onScreenDismiss(type: type)
}
}
// MARK: - Alerts
enum ___VARIABLE_sceneName___AlertType: RouterAlertScreenProtocol {
case error(title: String, message: String)
}
extension ___VARIABLE_sceneName___Router {
func getAlertTitle(for type: ___VARIABLE_sceneName___AlertType) -> Text? {
switch type {
case let .error(title, _):
return Text(title)
}
}
func getAlertMessage(for type: ___VARIABLE_sceneName___AlertType) -> some View {
switch type {
case let .error(_, message):
return Text(message)
}
}
func getAlertActions(for type: ___VARIABLE_sceneName___AlertType) -> some View {
Button("Cancel", role: .cancel, action: {})
}
}