-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPokitList.swift
More file actions
119 lines (107 loc) ยท 3.49 KB
/
PokitList.swift
File metadata and controls
119 lines (107 loc) ยท 3.49 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
//
// PokitList.swift
// DSKit
//
// Created by ๊น๋ํ on 7/1/24.
//
import SwiftUI
import Util
import NukeUI
public struct PokitList<Item: PokitSelectItem>: View {
@Namespace
private var heroEffect
private let selectedItem: Item?
private let list: [Item]
private let isDisabled: Bool
private let action: (Item) -> Void
public init(
selectedItem: Item?,
list: [Item],
isDisabled: Bool = false,
action: @escaping (Item) -> Void
) {
self.selectedItem = selectedItem
self.list = list
self.isDisabled = isDisabled
self.action = action
}
public var body: some View {
if list.isEmpty {
PokitCaution(type: .์นดํ
๊ณ ๋ฆฌ์์)
} else {
ScrollView {
VStack(spacing: 0) {
ForEach(self.list) { item in
listCell(item)
.pokitScrollTransition(.opacity)
}
}
}
.background(Color.pokit(.bg(.base)))
}
}
@ViewBuilder
private func listCell(_ item: Item) -> some View {
let isSelected = self.selectedItem?.id == item.id
Button {
action(item)
} label: {
HStack(spacing: 12) {
if item.categoryName == Constants.๋ฏธ๋ถ๋ฅ {
Image(.image(.unpokited))
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 60, height: 60)
} else {
thumbNail(url: item.categoryImage.imageURL)
}
VStack(alignment: .leading, spacing: 4) {
Text(item.categoryName)
.pokitFont(.b1(.b))
.foregroundStyle(
isDisabled
? .pokit(.text(.disable))
: .pokit(.text(.primary))
)
Text("๋งํฌ \(item.contentCount)๊ฐ")
.pokitFont(.detail1)
.foregroundStyle(
isDisabled
? .pokit(.text(.disable))
: .pokit(.text(.tertiary))
)
}
Spacer()
}
.padding(.vertical, 12)
.padding(.horizontal, 20)
.background(if: isSelected) {
Color.pokit(.bg(.primary))
.matchedGeometryEffect(id: "SELECT", in: heroEffect)
} else: {
isDisabled
? Color.pokit(.bg(.disable))
: Color.pokit(.bg(.base))
}
}
.animation(.pokitDissolve, value: isSelected)
.disabled(isDisabled)
}
@MainActor
private func thumbNail(url: String) -> some View {
LazyImage(url: URL(string: url)) { state in
Group {
if let image = state.image {
image
.resizable()
} else {
PokitSpinner()
.foregroundStyle(.pokit(.icon(.brand)))
.frame(width: 48, height: 48)
}
}
.animation(.pokitDissolve, value: state.image)
}
.frame(width: 60, height: 60)
}
}