-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPokitCategorySettingView.swift
More file actions
252 lines (240 loc) Β· 8.32 KB
/
PokitCategorySettingView.swift
File metadata and controls
252 lines (240 loc) Β· 8.32 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//
// PokitCategorySettingView.swift
// Feature
//
// Created by κΉλ―ΌνΈ on 7/25/24.
import SwiftUI
import ComposableArchitecture
import Domain
import DSKit
import Util
import NukeUI
@ViewAction(for: PokitCategorySettingFeature.self)
public struct PokitCategorySettingView: View {
/// - Properties
@Perception.Bindable
public var store: StoreOf<PokitCategorySettingFeature>
@FocusState private var isFocused: Bool
/// - Initializer
public init(store: StoreOf<PokitCategorySettingFeature>) {
self.store = store
}
}
//MARK: - View
public extension PokitCategorySettingView {
var body: some View {
WithPerceptionTracking {
VStack(spacing: 0) {
thumbnailSection
pokitNameSection
PokitDivider()
.padding(.horizontal, -20)
.padding(.top, 28)
openTypeSettingSection
keywordSection
Spacer()
}
.padding(.top, 16)
.overlay(alignment: .bottom) {
saveButton
.padding(.bottom, store.isKeyboardVisible ? -26 : 0)
.padding(.bottom, 36)
}
.padding(.horizontal, 20)
.padding(.top, 16)
// .pokitMaxWidth()
.pokitNavigationBar { navigationBar }
.sheet(isPresented: $store.isProfileSheetPresented) {
PokitProfileBottomSheet(
selectedImage: store.selectedProfile,
images: store.profileImages,
delegateSend: { store.send(.scope(.profile($0))) }
)
}
.sheet(isPresented: $store.isKeywordSheetPresented) {
PokitKeywordBottomSheet(
selectedKeywordType: store.selectedKeywordType,
action: { send(.ν€μλ_μ ν_λ²νΌ_λλ μλ($0)) }
)
}
.ignoresSafeArea(.container, edges: .bottom)
.task { await send(.λ·°κ°_λνλ¬μλ).finish() }
}
}
}
//MARK: - Configure View
private extension PokitCategorySettingView {
var navigationBar: some View {
PokitHeader(title: store.type.title) {
PokitHeaderItems(placement: .leading) {
PokitToolbarButton(.icon(.arrowLeft)) {
send(.dismiss)
}
}
}
.padding(.top, 8)
}
/// μΈλ€μΌμ΄λ―Έμ§ +νλ‘ν μ€μ
@MainActor
var thumbnailSection: some View {
LazyImage(
url: URL(string: store.selectedProfile?.imageURL ?? ""),
transaction: .init(animation: .spring)
) { phase in
if let image = phase.image {
Circle().foregroundStyle(.pokit(.bg(.primary)))
.overlay {
image
.resizable()
.padding(10)
.clipShape(.circle)
}
} else {
WithPerceptionTracking {
ZStack {
Color.pokit(.bg(.primary))
if store.selectedProfile?.imageURL != nil {
PokitSpinner()
.foregroundStyle(.pokit(.icon(.brand)))
.frame(width: 48, height: 48)
}
}
.clipShape(.circle)
}
}
}
.frame(width: 80, height: 80)
.overlay(alignment: .bottomTrailing) {
Circle()
.stroke(
.pokit(.icon(.tertiary)),
lineWidth: 1
)
.frame(width: 24, height: 24)
.background {
ZStack {
Circle()
.foregroundStyle(
.pokit(.icon(.inverseWh))
)
Button(action: { send(.νλ‘ν_μ€μ _λ²νΌ_λλ μλ) }) {
Image(.icon(.edit))
.resizable()
.frame(width: 18, height: 18)
.foregroundStyle(.pokit(.icon(.tertiary)))
.padding(2)
}
}
}
.offset(x: 10)
.padding(.bottom, 3)
}
}
/// νμ΄ν + ν
μ€νΈνλλ₯Ό ν¬ν¨ν ν¬ν·λͺ
μ
λ ₯ μΉμ
var pokitNameSection: some View {
VStack(alignment: .leading, spacing: 8) {
Text("ν¬ν·λͺ
")
.pokitFont(.b2(.m))
.foregroundStyle(.pokit(.text(.secondary)))
PokitTextInput(
text: $store.categoryName,
type: store.categoryName.isEmpty ? .text : .iconR(
icon: .icon(.x),
action: { send(.ν¬ν·λͺ
μ§μ°κΈ°_λ²νΌ_λλ μλ) }
),
shape: .rectangle,
state: $store.pokitNameTextInpuState,
placeholder: "ν¬ν·λͺ
μ μ
λ ₯ν΄μ£ΌμΈμ.",
maxLetter: 10,
focusState: $isFocused,
equals: true
)
}
}
/// κ³΅κ° μ¬λΆ μ€μ
var openTypeSettingSection: some View {
VStack(alignment: .leading, spacing: 4) {
Toggle(isOn: $store.isPublicType) {
Text("μ 체 곡κ°λ‘ μ€μ νκΈ°")
.pokitFont(.b1(.b))
.foregroundStyle(.pokit(.text(.primary)))
}
.tint(.pokit(.icon(.brand)))
Text("ν¬ν·μ μ μ₯λ λ§ν¬κ° λ€λ₯Έ μ¬μ©μμκ² μΆμ²λ©λλ€.")
.pokitFont(.detail1)
.foregroundStyle(.pokit(.text(.tertiary)))
}
.padding(.vertical, 12)
.padding(.leading, 8)
.padding(.top, 16)
}
/// ν¬ν· ν€μλ
var keywordSection: some View {
Group {
if store.isPublicType {
VStack(alignment: .leading, spacing: 4) {
Button(action: { send(.ν€μλ_λ°ν
μνΈ_νμ±ν(true)) }) {
Text("ν¬ν· ν€μλ")
.pokitFont(.b1(.b))
.foregroundStyle(.pokit(.text(.primary)))
Spacer()
Image(.icon(.arrowRight))
}
.buttonStyle(.plain)
Text(store.keywordSelectType.label)
.pokitFont(.detail1)
.foregroundStyle(store.keywordSelectType.fontColor)
}
.padding(.vertical, 12)
.padding(.leading, 8)
.padding(.top, 8)
}
}
.animation(.smooth, value: store.isPublicType)
}
/// μ μ₯νκΈ° λ²νΌ
var saveButton: some View {
PokitBottomButton(
"μ μ₯νκΈ°",
state: !store.categoryName.isEmpty && store.selectedProfile != nil
? .filled(.primary)
: .disable,
action: { send(.μ μ₯_λ²νΌ_λλ μλ) }
)
}
/// λ΄ν¬ν· Item
struct PokitItem: View {
let item: BaseCategoryItem
init(item: BaseCategoryItem) {
self.item = item
}
var body: some View {
VStack(alignment: .leading, spacing: 4) {
HStack {
Text(item.categoryName)
.pokitFont(.b1(.b))
.foregroundStyle(.pokit(.text(.disable)))
Spacer()
}
HStack {
Text("λ§ν¬ \(item.contentCount)κ°")
.pokitFont(.detail1)
.foregroundStyle(.pokit(.text(.disable)))
Spacer()
}
}
.padding(.vertical, 12)
}
}
}
//MARK: - Preview
#Preview {
NavigationStack {
PokitCategorySettingView(
store: Store(
initialState: .init(type: .μΆκ°),
reducer: { PokitCategorySettingFeature() }
)
)
}
}