-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
EmptyConfigurationView.swift
159 lines (138 loc) · 5.07 KB
/
EmptyConfigurationView.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import SwiftUI
struct EmptyConfigurationView: View {
enum Action {
case empty
case initial
}
@State var done: Bool = false
@State var selected: Action = .initial
private let colors = SplashColors(primaryColor: Color(.systemGreen),
secondaryColor: Color(.systemBlue),
backgroundColor: Color(.sRGB, red: 0.03, green: 0.11, blue: 0.25, opacity: 1.0))
private let namespace: Namespace.ID
private let onAction: (Action) -> Void
private let model = KeyboardCowboyConfiguration.default()
init(_ namespace: Namespace.ID, onAction: @escaping (Action) -> Void) {
self.namespace = namespace
self.onAction = onAction
}
var body: some View {
VStack(spacing: 0) {
Text("Choose your configuration")
.font(.title)
.frame(maxWidth: .infinity, alignment: .center)
.padding(32)
Divider()
HStack(spacing: 48) {
Button(action: {
selected = .initial
}, label: {
LazyVGrid(columns: [
.init(.adaptive(minimum: 24)),
.init(.adaptive(minimum: 24)),
.init(.adaptive(minimum: 24)),
.init(.adaptive(minimum: 24)),
.init(.adaptive(minimum: 24)),
], spacing: 12) {
ForEach(model.groups) { group in
GroupIconView(color: group.color,
icon: nil,
symbol: group.symbol)
.frame(width: 24, height: 24)
.shadow(color: .black.opacity(0.3), radius: 1, y: 2)
}
}
})
.buttonStyle(EmptyConfigurationButtonStyle(title: "Default",
subtitle: "Recommended",
action: .initial,
selected: $selected))
Button(action: {
selected = .empty
}, label: {
GroupIconView(color: "#000",
icon: nil,
symbol: "app.dashed")
.frame(width: 30, height: 30)
.shadow(color: .black.opacity(0.3), radius: 1, y: 2)
})
.buttonStyle(EmptyConfigurationButtonStyle(title: "Empty",
subtitle: " ",
action: .empty,
selected: $selected))
}
.padding(16)
.frame(maxWidth: .infinity)
.background(.black.opacity(0.5))
Divider()
Text("To get started, you can either select an empty configuration or choose from our prefilled configurations with default groups.\n\nSimply tap on the option you prefer and you'll be ready to go!")
.font(.title3)
.frame(maxWidth: .infinity, alignment: .center)
.padding(.vertical, 8)
.padding(.horizontal, 64)
Button(action: {
onAction(selected)
}, label: {
Text("Confirm")
})
.buttonStyle(.zen(.init(color: .systemGreen, hoverEffect: .constant(false))))
.padding(.vertical)
.matchedGeometryEffect(id: "initial-item", in: namespace)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.background(SplashView(colors: colors, done: $done))
}
}
struct EmptyConfigurationButtonStyle: ButtonStyle {
let title: String
let subtitle: String
var action: EmptyConfigurationView.Action
@Binding var selected: EmptyConfigurationView.Action
func makeBody(configuration: Configuration) -> some View {
VStack {
Text(title)
configuration.label
.buttonStyle(.plain)
.frame(width: 188, height: 80)
.clipped()
.background(
EmptyConfigurationBackgroundView(action: action,
selected: $selected)
)
Text(subtitle)
.font(.footnote)
}
}
}
struct EmptyConfigurationBackgroundView: View {
@State var action: EmptyConfigurationView.Action
@Binding var selected: EmptyConfigurationView.Action
var body: some View {
let color: NSColor = action == .initial ? .systemGreen : .systemGray
let selected = action == selected
ZStack {
RoundedRectangle(cornerRadius: 8)
.stroke(Color(.systemGreen).opacity(0.5), lineWidth: 6)
.opacity(selected ? 1 : 0)
LinearGradient(stops: [
.init(color: Color(color), location: 0.0),
.init(color: Color(color.blended(withFraction: 0.3, of: .black)!), location: 0.025),
.init(color: Color(color.blended(withFraction: 0.5, of: .black)!), location: 1.0),
], startPoint: .top, endPoint: .bottom)
.cornerRadius(8)
}
.shadow(
color: selected
? Color(.systemGreen)
: Color(.sRGBLinear, white: 0, opacity: 0.33),
radius: 4)
.animation(.default, value: selected)
}
}
struct EmptyConfigurationView_Previews: PreviewProvider {
@Namespace static var namespace
static var previews: some View {
EmptyConfigurationView(namespace) { _ in }
.previewLayout(.sizeThatFits)
}
}