|
8 | 8 | import SwiftUI |
9 | 9 |
|
10 | 10 | import Util |
| 11 | +import NukeUI |
11 | 12 |
|
12 | 13 | public struct PokitList<Item: PokitSelectItem>: View { |
13 | 14 | @Namespace |
14 | 15 | private var heroEffect |
15 | 16 |
|
16 | 17 | private let selectedItem: Item? |
17 | 18 | private let list: [Item] |
| 19 | + private let isDisabled: Bool |
18 | 20 | private let action: (Item) -> Void |
19 | 21 |
|
20 | 22 | public init( |
21 | 23 | selectedItem: Item?, |
22 | 24 | list: [Item], |
| 25 | + isDisabled: Bool = false, |
23 | 26 | action: @escaping (Item) -> Void |
24 | 27 | ) { |
25 | 28 | self.selectedItem = selectedItem |
26 | 29 | self.list = list |
| 30 | + self.isDisabled = isDisabled |
27 | 31 | self.action = action |
28 | 32 | } |
29 | 33 |
|
@@ -54,29 +58,61 @@ public struct PokitList<Item: PokitSelectItem>: View { |
54 | 58 | Button { |
55 | 59 | action(item) |
56 | 60 | } label: { |
57 | | - HStack { |
| 61 | + HStack(spacing: 12) { |
| 62 | + thumbNail(url: item.categoryImage.imageURL) |
| 63 | + |
58 | 64 | VStack(alignment: .leading, spacing: 4) { |
59 | 65 | Text(item.categoryName) |
60 | 66 | .pokitFont(.b1(.b)) |
61 | | - .foregroundStyle(.pokit(.text(.primary))) |
| 67 | + .foregroundStyle( |
| 68 | + isDisabled |
| 69 | + ? .pokit(.text(.disable)) |
| 70 | + : .pokit(.text(.primary)) |
| 71 | + ) |
62 | 72 |
|
63 | 73 | Text("링크 \(item.contentCount)개") |
64 | 74 | .pokitFont(.detail1) |
65 | | - .foregroundStyle(.pokit(.text(.tertiary))) |
| 75 | + .foregroundStyle( |
| 76 | + isDisabled |
| 77 | + ? .pokit(.text(.disable)) |
| 78 | + : .pokit(.text(.tertiary)) |
| 79 | + ) |
66 | 80 | } |
67 | 81 |
|
68 | 82 | Spacer() |
69 | 83 | } |
70 | | - .padding(.leading, 28) |
71 | | - .padding(.trailing, 20) |
72 | | - .padding(.vertical, 13) |
| 84 | + .padding(.vertical, 18) |
| 85 | + .padding(.horizontal, 20) |
73 | 86 | .background { |
74 | 87 | if isSelected { |
75 | 88 | Color.pokit(.bg(.primary)) |
76 | 89 | .matchedGeometryEffect(id: "SELECT", in: heroEffect) |
| 90 | + } else { |
| 91 | + isDisabled |
| 92 | + ? Color.pokit(.bg(.disable)) |
| 93 | + : Color.pokit(.bg(.base)) |
77 | 94 | } |
78 | 95 | } |
79 | 96 | } |
80 | 97 | .animation(.pokitDissolve, value: isSelected) |
| 98 | + .disabled(isDisabled) |
| 99 | + } |
| 100 | + |
| 101 | + @MainActor |
| 102 | + private func thumbNail(url: String) -> some View { |
| 103 | + LazyImage(url: URL(string: url)) { state in |
| 104 | + Group { |
| 105 | + if let image = state.image { |
| 106 | + image |
| 107 | + .resizable() |
| 108 | + } else { |
| 109 | + PokitSpinner() |
| 110 | + .foregroundStyle(.pokit(.icon(.brand))) |
| 111 | + .frame(width: 48, height: 48) |
| 112 | + } |
| 113 | + } |
| 114 | + .animation(.pokitDissolve, value: state.image) |
| 115 | + } |
| 116 | + .frame(width: 60, height: 60) |
81 | 117 | } |
82 | 118 | } |
0 commit comments