Skip to content

Commit 85ccf27

Browse files
ShapeKim98stealmh
authored andcommitted
[refactor] #173 PokitSelect에 PokitSelectSheet 적용
1 parent 38543a0 commit 85ccf27

File tree

2 files changed

+19
-64
lines changed

2 files changed

+19
-64
lines changed

Projects/DSKit/Sources/Components/PokitSelect.swift

Lines changed: 12 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,18 @@ public struct PokitSelect<Item: PokitSelectItem>: View {
5050
}
5151
.onChange(of: selectedItem) { onChangedSeletedItem($0) }
5252
.sheet(isPresented: $showSheet) {
53-
listSheet
54-
.presentationDragIndicator(.visible)
55-
.pokitPresentationCornerRadius()
56-
.presentationDetents([.height(564)])
57-
.pokitPresentationBackground()
53+
PokitSelectSheet(
54+
list: list,
55+
itemSelected: { item in
56+
listDismiss()
57+
action(item)
58+
},
59+
pokitAddAction: addAction
60+
)
61+
.presentationDragIndicator(.visible)
62+
.pokitPresentationCornerRadius()
63+
.presentationDetents([.height(564)])
64+
.pokitPresentationBackground()
5865
}
5966
}
6067

@@ -96,63 +103,6 @@ public struct PokitSelect<Item: PokitSelectItem>: View {
96103
.animation(.pokitDissolve, value: self.state)
97104
}
98105

99-
private var listSheet: some View {
100-
Group {
101-
if let list {
102-
VStack(spacing: 0) {
103-
if let addAction {
104-
addButton {
105-
listDismiss()
106-
addAction()
107-
}
108-
}
109-
110-
PokitList(
111-
selectedItem: selectedItem,
112-
list: list
113-
) { item in
114-
action(item)
115-
listCellTapped(item)
116-
}
117-
}
118-
.padding(.top, 12)
119-
.padding(.bottom, 20)
120-
} else {
121-
PokitLoading()
122-
}
123-
}
124-
}
125-
126-
@ViewBuilder
127-
private func addButton(
128-
action: @escaping () -> Void
129-
) -> some View {
130-
Button(action: action) {
131-
HStack(spacing: 20) {
132-
PokitIconButton(
133-
.icon(.plusR),
134-
state: .default(.secondary),
135-
size: .medium,
136-
shape: .round,
137-
action: action
138-
)
139-
140-
Text("포킷 추가하기")
141-
.pokitFont(.b1(.b))
142-
.foregroundStyle(.pokit(.text(.primary)))
143-
144-
Spacer()
145-
}
146-
.padding(.vertical, 22)
147-
.padding(.horizontal, 30)
148-
.background(alignment: .bottom) {
149-
Rectangle()
150-
.fill(.pokit(.border(.tertiary)))
151-
.frame(height: 1)
152-
}
153-
}
154-
}
155-
156106
private func partSelectButtonTapped() {
157107
showSheet = true
158108
}

Projects/DSKit/Sources/Components/PokitSelectSheet.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ import Util
1010

1111

1212
public struct PokitSelectSheet<Item: PokitSelectItem>: View {
13+
@Binding
14+
private var selectedItem: Item?
15+
1316
private let list: [Item]?
1417
private let itemSelected: (Item) -> Void
1518
private let pokitAddAction: (() -> Void)?
1619

1720
public init(
1821
list: [Item]?,
22+
selectedItem: Binding<Item?> = .constant(nil),
1923
itemSelected: @escaping (Item) -> Void,
2024
pokitAddAction: (() -> Void)?
2125
) {
2226
self.list = list
27+
self._selectedItem = selectedItem
2328
self.itemSelected = itemSelected
2429
self.pokitAddAction = pokitAddAction
2530
}
@@ -35,10 +40,10 @@ public struct PokitSelectSheet<Item: PokitSelectItem>: View {
3540
}
3641
}
3742
PokitList(
38-
selectedItem: nil,
43+
selectedItem: selectedItem,
3944
list: list
4045
) { item in
41-
itemSelected(item)
46+
itemSelected(item)
4247
}
4348
}
4449
.padding(.top, 12)

0 commit comments

Comments
 (0)