-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainTabFeatureView.swift
More file actions
362 lines (335 loc) Β· 12.6 KB
/
MainTabFeatureView.swift
File metadata and controls
362 lines (335 loc) Β· 12.6 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
//
// MainTabView.swift
// App
//
// Created by κΉλ―ΌνΈ on 7/11/24.
import SwiftUI
import ComposableArchitecture
import DSKit
import FeaturePokit
import FeatureRecommend
import FeatureSetting
import FeatureCategorySetting
import FeatureContentDetail
import FeatureContentSetting
import FeatureCategoryDetail
import FeatureContentList
import FeatureCategorySharing
@ViewAction(for: MainTabFeature.self)
public struct MainTabView: View {
/// - Properties
@Perception.Bindable
public var store: StoreOf<MainTabFeature>
/// - Initializer
public init(store: StoreOf<MainTabFeature>) {
self.store = store
UITabBar.appearance().isHidden = true
}
}
//MARK: - View
public extension MainTabView {
var body: some View {
WithPerceptionTracking {
NavigationStack(path: $store.scope(state: \.path, action: \.path)) {
content
} destination: { store in
WithPerceptionTracking {
ZStack(alignment: .bottom) {
switch store.state {
case .μλ¦Όν¨:
if let store = store.scope(state: \.μλ¦Όν¨, action: \.μλ¦Όν¨) {
PokitAlertBoxView(store: store)
}
case .κ²μ:
if let store = store.scope(state: \.κ²μ, action: \.κ²μ) {
PokitSearchView(store: store)
}
case .μ€μ :
if let store = store.scope(state: \.μ€μ , action: \.μ€μ ) {
PokitSettingView(store: store)
}
case .ν¬ν·μΆκ°λ°μμ :
if let store = store.scope(state: \.ν¬ν·μΆκ°λ°μμ , action: \.ν¬ν·μΆκ°λ°μμ ) {
PokitCategorySettingView(store: store)
}
case .λ§ν¬μΆκ°λ°μμ :
if let store = store.scope(state: \.λ§ν¬μΆκ°λ°μμ , action: \.λ§ν¬μΆκ°λ°μμ ) {
ContentSettingView(store: store)
}
case .μΉ΄ν
κ³ λ¦¬μμΈ:
if let store = store.scope(state: \.μΉ΄ν
κ³ λ¦¬μμΈ, action: \.μΉ΄ν
κ³ λ¦¬μμΈ) {
CategoryDetailView(store: store)
}
case .λ§ν¬λͺ©λ‘:
if let store = store.scope(state: \.λ§ν¬λͺ©λ‘, action: \.λ§ν¬λͺ©λ‘) {
ContentListView(store: store)
}
case .λ§ν¬κ³΅μ :
if let store = store.scope(state: \.λ§ν¬κ³΅μ , action: \.λ§ν¬κ³΅μ ) {
CategorySharingView(store: store)
}
}
if self.store.linkPopup != nil {
PokitLinkPopup(type: $store.linkPopup)
.onAction { send(.λ§ν¬νμ
_λ²νΌ_λλ μλ, animation: .pokitSpring) }
}
}
}
}
.onOpenURL { send(.onOpenURL(url: $0)) }
}
}
}
//MARK: - Configure View
private extension MainTabView {
var content: some View {
tabView
.overlay(alignment: .bottom) {
VStack(spacing: 0) {
if store.linkPopup != nil {
PokitLinkPopup(type: $store.linkPopup)
.onAction { send(.λ§ν¬νμ
_λ²νΌ_λλ μλ, animation: .pokitSpring) }
.padding(.bottom, 20)
}
bottomTabBar
}
}
.ignoresSafeArea(edges: .bottom)
.sheet(isPresented: $store.isBottomSheetPresented) {
///Todo: bottom sheet μΆκ°
AddSheet(action: { send(.addSheetTypeSelected($0)) })
}
.sheet(
item: $store.scope(
state: \.contentDetail,
action: \.contentDetail
)
) { store in
ContentDetailView(store: store)
}
.sheet(isPresented: $store.isErrorSheetPresented) {
PokitAlert(
store.error?.title ?? "μλ¬",
message: store.error?.message ?? "λ©μΈμ§",
confirmText: "νμΈ",
action: { send(.κ²½κ³ _νμΈλ²νΌ_ν΄λ¦) }
)
}
.task { await send(.onAppear).finish() }
}
var tabView: some View {
TabView(selection: $store.selectedTab) {
switch store.selectedTab {
case .pokit:
PokitRootView(store: store.scope(state: \.pokit, action: \.pokit))
.pokitNavigationBar { pokitNavigationBar }
.toolbarBackground(.hidden, for: .tabBar)
case .recommend:
RecommendView(store: store.scope(state: \.recommend, action: \.recommend))
.pokitNavigationBar { remindNavigationBar }
.toolbarBackground(.hidden, for: .tabBar)
}
}
}
var pokitNavigationBar: some View {
PokitHeader {
PokitHeaderItems(placement: .leading) {
Image(.logo(.pokit))
.resizable()
.frame(width: 104, height: 32)
.foregroundStyle(.pokit(.icon(.brand)))
}
PokitHeaderItems(placement: .trailing) {
PokitToolbarButton(
.icon(.search),
action: { store.send(.pokit(.view(.κ²μ_λ²νΌ_λλ μλ))) }
)
PokitToolbarButton(
.icon(.bell),
action: { store.send(.pokit(.view(.μλ_λ²νΌ_λλ μλ))) }
)
PokitToolbarButton(
.icon(.setup),
action: { store.send(.pokit(.view(.μ€μ _λ²νΌ_λλ μλ))) }
)
}
}
.padding(.vertical, 8)
}
var remindNavigationBar: some View {
PokitHeader {
PokitHeaderItems(placement: .leading) {
Text("λ§ν¬μΆμ²")
.pokitFont(.title2)
.foregroundStyle(.pokit(.text(.primary)))
}
PokitHeaderItems(placement: .trailing) {
PokitToolbarButton(
.icon(.search),
action: { send(.κ²μ_λ²νΌ_λλ μλ) }
)
PokitToolbarButton(
.icon(.bell),
action: { send(.μλ¦Ό_λ²νΌ_λλ μλ) }
)
}
}
.padding(.vertical, 8)
}
var bottomTabBar: some View {
HStack(alignment: .bottom, spacing: 0) {
bottomTabBarItem(.pokit)
Spacer()
bottomTabBarItem(.recommend)
}
.padding(.horizontal, 48)
.padding(.top, 12)
.padding(.bottom, 36)
.background {
Rectangle()
.roundedCorner(20, corners: [.topLeft, .topRight])
.foregroundStyle(.pokit(.bg(.base)))
.pokitShadow(
x: 0,
y: -2,
blur: 20,
spread: 0,
color: Color.black,
colorPercent: 10
)
}
.padding(.top, 30)
.overlay(alignment: .top) {
Button(action: { send(.addButtonTapped) }) {
Image(.icon(.plus))
.resizable()
.frame(width: 36, height: 36)
.padding(12)
.foregroundStyle(.pokit(.icon(.inverseWh)))
.background {
RoundedRectangle(cornerRadius: 9999, style: .continuous)
.fill(.pokit(.bg(.brand)))
}
.frame(width: 60, height: 60)
}
}
.pokitMaxWidth()
.animation(.pokitDissolve, value: store.selectedTab)
}
@ViewBuilder
func bottomTabBarItem(_ tab: MainTab) -> some View {
let isSelected: Bool = store.selectedTab == tab
VStack(spacing: 4) {
Image(tab.icon)
.renderingMode(.template)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 24, height: 24)
.foregroundStyle(
isSelected
? .pokit(.icon(.primary))
: .pokit(.icon(.tertiary))
)
Text(tab.title)
.foregroundStyle(
isSelected
? .pokit(.text(.primary))
: .pokit(.text(.tertiary))
)
.pokitFont(.detail2)
}
.padding(.horizontal, 28)
.onTapGesture {
UIImpactFeedbackGenerator(style: .light)
.impactOccurred()
store.send(.binding(.set(\.selectedTab, tab)))
}
}
struct AddSheet: View {
@State private var height: CGFloat = 0
var action: (TabAddSheetType) -> Void
var body: some View {
GeometryReader { proxy in
let bottomPadding: CGFloat = {
if #available(iOS 26.0, *) {
return 32
} else {
return 48
}
}()
HStack(spacing: 20) {
Spacer()
ForEach(TabAddSheetType.allCases, id: \.self) { type in
Button(action: { action(type) }) {
VStack(spacing: 4) {
Spacer()
type.icon
.renderingMode(.template)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 28, height: 28)
.foregroundStyle(.pokit(.icon(.inverseWh)))
Text(type.title)
.pokitFont(.b3(.m))
.foregroundStyle(.pokit(.text(.inverseWh)))
Spacer()
}
.padding(.horizontal, 24)
.background {
RoundedRectangle(cornerRadius: 12, style: .continuous)
.foregroundStyle(.pokit(.bg(.brand)))
}
.frame(height: 96)
}
}
Spacer()
}
.padding(.bottom, bottomPadding)
.padding(.top, 36)
.pokitPresentationCornerRadius()
.pokitPresentationBackground()
.presentationDragIndicator(.visible)
.readHeight()
.onPreferenceChange(HeightPreferenceKey.self) { height in
if let height {
self.height = height
}
}
.presentationDetents([.height(self.height)])
}
.ignoresSafeArea(edges: .bottom)
}
}
}
//MARK: - Preview
#Preview {
MainTabView(
store: Store(
initialState: .init(),
reducer: { MainTabFeature() }
)
)
}
//MARK: - ν¬ν·, 리λ§μΈλ μΆκ°λλ©΄ μ§μ°κΈ°
public struct TestView1: View {
public var body: some View {
ZStack {
Color.red
HStack {
Text("Pokit View")
.font(.largeTitle)
}
}
}
}
public struct TestView2: View {
public var body: some View {
ZStack {
Color.blue
HStack {
Text("Remind View")
.font(.largeTitle)
}
}
}
}