Skip to content

Commit 2be13ce

Browse files
committed
[feat] #171 overlay, background 모디파이어 개선
1 parent 3c2d639 commit 2be13ce

File tree

3 files changed

+82
-13
lines changed

3 files changed

+82
-13
lines changed

Projects/DSKit/Sources/Components/PokitHeader.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import SwiftUI
99

10+
import Util
11+
1012
public struct PokitHeader<Content: View>: View {
1113
private let title: String?
1214

@@ -28,12 +30,10 @@ public struct PokitHeader<Content: View>: View {
2830
.padding(.horizontal, 20)
2931
.padding(.vertical, 12)
3032
.background(.pokit(.bg(.base)))
31-
.overlay {
32-
if let title {
33-
Text(title)
34-
.pokitFont(.title3)
35-
.foregroundStyle(.pokit(.text(.primary)))
36-
}
33+
.overlay(ifLet: title) { title in
34+
Text(title)
35+
.pokitFont(.title3)
36+
.foregroundStyle(.pokit(.text(.primary)))
3737
}
3838
}
3939
}

Projects/Feature/FeatureContentDetail/Sources/ContentDetail/ContentDetailView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import SwiftUI
99
import ComposableArchitecture
1010
import Domain
1111
import DSKit
12+
import Util
1213

1314
@ViewAction(for: ContentDetailFeature.self)
1415
public struct ContentDetailView: View {
@@ -52,10 +53,8 @@ public extension ContentDetailView {
5253
.pokitPresentationCornerRadius()
5354
.presentationDragIndicator(.visible)
5455
.presentationDetents([.height(588), .large])
55-
.overlay(alignment: .bottom) {
56-
if store.linkPopup != nil {
57-
PokitLinkPopup(type: $store.linkPopup)
58-
}
56+
.overlay(if: store.linkPopup != nil, alignment: .bottom) {
57+
PokitLinkPopup(type: $store.linkPopup)
5958
}
6059
.sheet(isPresented: $store.showAlert) {
6160
PokitAlert(

Projects/Util/Sources/Extension/View+Extension.swift

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
import SwiftUI
99

10-
extension View {
11-
public func dismissKeyboard(
10+
public extension View {
11+
@ViewBuilder
12+
func dismissKeyboard(
1213
focused: FocusState<Bool>.Binding
1314
) -> some View {
1415
self
@@ -23,7 +24,8 @@ extension View {
2324
}
2425
}
2526

26-
public func dismissKeyboard<Value: Hashable>(
27+
@ViewBuilder
28+
func dismissKeyboard<Value: Hashable>(
2729
focused: FocusState<Value?>.Binding
2830
) -> some View {
2931
self
@@ -37,4 +39,72 @@ extension View {
3739
}
3840
}
3941
}
42+
43+
@ViewBuilder
44+
func overlay<V>(
45+
`if` condition: Bool,
46+
alignment: Alignment = .center,
47+
@ViewBuilder content: () -> V,
48+
@ViewBuilder `else`: () -> V? = { nil }
49+
) -> some View where V : View {
50+
self
51+
.overlay(alignment: alignment) {
52+
if condition {
53+
content()
54+
} else {
55+
`else`()
56+
}
57+
}
58+
}
59+
60+
@ViewBuilder
61+
func overlay<V, T>(
62+
ifLet optional: T?,
63+
alignment: Alignment = .center,
64+
@ViewBuilder content: (T) -> V,
65+
@ViewBuilder `else`: () -> V? = { nil }
66+
) -> some View where V : View {
67+
self
68+
.overlay(alignment: alignment) {
69+
if let optional {
70+
content(optional)
71+
} else {
72+
`else`()
73+
}
74+
}
75+
}
76+
77+
@ViewBuilder
78+
func background<V>(
79+
`if` condition: Bool,
80+
alignment: Alignment = .center,
81+
@ViewBuilder content: () -> V,
82+
@ViewBuilder `else`: () -> V? = { nil }
83+
) -> some View where V : View {
84+
self
85+
.background(alignment: alignment) {
86+
if condition {
87+
content()
88+
} else {
89+
`else`()
90+
}
91+
}
92+
}
93+
94+
@ViewBuilder
95+
func background<V, T>(
96+
ifLet optional: T?,
97+
alignment: Alignment = .center,
98+
@ViewBuilder content: (T) -> V,
99+
@ViewBuilder `else`: () -> V? = { nil }
100+
) -> some View where V : View {
101+
self
102+
.background(alignment: alignment) {
103+
if let optional {
104+
content(optional)
105+
} else {
106+
`else`()
107+
}
108+
}
109+
}
40110
}

0 commit comments

Comments
 (0)