Skip to content

Commit 0b2523a

Browse files
committed
[refactor] #203 PokitLinkPopup 선언형으로 리팩토링
1 parent e338c4d commit 0b2523a

File tree

3 files changed

+49
-25
lines changed

3 files changed

+49
-25
lines changed

Projects/DSKit/Sources/Components/PokitLinkPopup.swift

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,36 @@ public struct PokitLinkPopup: View {
1515
@State
1616
private var second: Int = 0
1717
private let action: (() -> Void)?
18+
private let until: Int
1819
private let timer = Timer.publish(
1920
every: 1,
2021
on: .main,
2122
in: .common
2223
).autoconnect()
2324

24-
public init(
25+
public init(type: Binding<PokitLinkPopup.PopupType?>) {
26+
self._type = type
27+
switch type.wrappedValue {
28+
case let .link(_, _, until),
29+
let .text(_, until),
30+
let .success(_, until),
31+
let .error(_, until),
32+
let .warning(_, until),
33+
let .report(_, until):
34+
self.until = until
35+
default:
36+
self.until = 2
37+
}
38+
self.action = nil
39+
}
40+
41+
private init(
2542
type: Binding<PokitLinkPopup.PopupType?>,
26-
action: (() -> Void)? = nil
43+
until: Int,
44+
action: (() -> Void)?
2745
) {
2846
self._type = type
47+
self.until = until
2948
self.action = action
3049
}
3150

@@ -40,7 +59,7 @@ public struct PokitLinkPopup: View {
4059
.frame(width: 335, height: 60)
4160
.transition(.move(edge: .bottom).combined(with: .opacity))
4261
.onReceive(timer) { _ in
43-
guard second < 2 else {
62+
guard second < until else {
4463
closedPopup()
4564
return
4665
}
@@ -61,7 +80,7 @@ public struct PokitLinkPopup: View {
6180
.multilineTextAlignment(.leading)
6281
.foregroundStyle(textColor)
6382

64-
if case let .link(_, url) = type {
83+
if case let .link(_, url, _) = type {
6584
Text(url)
6685
.lineLimit(1)
6786
.pokitFont(.detail2)
@@ -167,26 +186,34 @@ public struct PokitLinkPopup: View {
167186

168187
private var title: String {
169188
switch type {
170-
case let .link(title, _),
171-
let .text(title),
172-
let .success(title),
173-
let .error(title),
174-
let .warning(title),
175-
let .report(title):
189+
case let .link(title, _, _),
190+
let .text(title, _),
191+
let .success(title, _),
192+
let .error(title, _),
193+
let .warning(title, _),
194+
let .report(title, _):
176195
return title
177196
default: return ""
178197
}
179198
}
199+
200+
public func onAction(_ action: @escaping () -> Void) -> Self {
201+
PokitLinkPopup(
202+
type: self.$type,
203+
until: self.until,
204+
action: action
205+
)
206+
}
180207
}
181208

182209
public extension PokitLinkPopup {
183210
enum PopupType: Equatable {
184-
case link(title: String, url: String)
185-
case text(title: String)
186-
case success(title: String)
187-
case error(title: String)
188-
case warning(title: String)
189-
case report(title: String)
211+
case link(title: String, url: String, until: Int = 2)
212+
case text(title: String, until: Int = 2)
213+
case success(title: String, until: Int = 2)
214+
case error(title: String, until: Int = 2)
215+
case warning(title: String, until: Int = 2)
216+
case report(title: String, until: Int = 2)
190217
}
191218
}
192219

Projects/Feature/FeatureContentSetting/Sources/ContentSetting/ContentSettingView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ public extension ContentSettingView {
4646
}
4747
.overlay(alignment: .bottom) {
4848
if store.linkPopup != nil {
49-
PokitLinkPopup(
50-
type: $store.linkPopup,
51-
action: { send(.링크팝업_버튼_눌렀을때, animation: .pokitSpring) }
52-
)
49+
PokitLinkPopup(type: $store.linkPopup)
50+
.onAction { send(.링크팝업_버튼_눌렀을때, animation: .pokitSpring) }
51+
5352
}
5453
}
5554
.pokitMaxWidth()

Projects/Feature/FeaturePokit/Sources/PokitLinkEditView.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ public extension PokitLinkEditView {
6363
}
6464
.overlay(alignment: .bottom) {
6565
if store.linkPopup != nil {
66-
PokitLinkPopup(
67-
type: $store.linkPopup,
68-
action: { send(.링크팝업_버튼_눌렀을때, animation: .pokitSpring) }
69-
)
70-
.pokitMaxWidth()
66+
PokitLinkPopup(type: $store.linkPopup)
67+
.onAction { send(.링크팝업_버튼_눌렀을때, animation: .pokitSpring) }
68+
.pokitMaxWidth()
7169
}
7270
}
7371
/// fullScreenCover를 통해 새로운 Destination을 만들었음

0 commit comments

Comments
 (0)