-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorView.swift
More file actions
90 lines (81 loc) · 2.38 KB
/
Copy pathColorView.swift
File metadata and controls
90 lines (81 loc) · 2.38 KB
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
//
// RedView.swift
// RouterExample
//
// Created by burt on 2021/03/05.
//
import SwiftUI
import Router
enum MyColor: String {
case red
case green
case blue
case yellow
case purple
case white
static func from(string: String) -> MyColor {
return MyColor(rawValue: string) ?? .white
}
}
struct ColorView: View {
@EnvironmentObject
var router: Router
var color: MyColor = .white
var body: some View {
VStack(spacing: 48) {
switch color {
case .red:
Button("Go to Green") {
router.route("myapp://color?color=green", .push)
}
case .green:
Button("Go to Blue") {
router.route("myapp://color?color=blue", .push)
}
case .blue:
Button(action: { router.route("myapp://color?color=yellow", .push) }) {
Text("Go to Yellow")
.foregroundColor(.white)
}
case .yellow:
Button("Go to Purple") {
router.route("myapp://color?color=purple", .push)
}
case .purple:
Button("Go to White") {
router.route("myapp://color?color=white", .push)
}
default:
Button("Go to Red") {
router.route("myapp://color?color=red", .push)
}
}
Button(action: { router.route("myapp://content?as_root=true", .sheet) }) {
Text("Go to Sheet")
.foregroundColor(.black)
}
Button(action: { router.popToRoot() }) {
Text("Pop To Root")
.foregroundColor(.black)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(makeColor(color: color).ignoresSafeArea())
}
private func makeColor(color: MyColor) -> Color {
switch color {
case .red:
return Color.red
case .blue:
return Color.blue
case .green:
return Color.green
case .yellow:
return Color.yellow
case .purple:
return Color.purple
case .white:
return Color.white
}
}
}