Skip to content

Commit 43adefa

Browse files
authored
Gardening (#89)
1 parent 9e644e5 commit 43adefa

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

Examples/Demo/Demo/PageView.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct PageView<Content: View, Link: View, Destination: View>: View {
1313
var body: some View {
1414
ZStack {
1515
Rectangle()
16-
.do {
16+
.modifier {
1717
if #available(iOS 16, tvOS 16, *) {
1818
$0.fill(color.gradient)
1919
} else {
@@ -111,9 +111,17 @@ extension PageView where Link == EmptyView, Destination == EmptyView {
111111
}
112112

113113
extension View {
114-
func `do`<ModifiedView: View>(
115-
@ViewBuilder modifierClosure: (Self) -> ModifiedView
116-
) -> some View {
117-
modifierClosure(self)
114+
/// Modify a view with a `ViewBuilder` closure.
115+
///
116+
/// This represents a streamlining of the
117+
/// [`modifier`](https://developer.apple.com/documentation/swiftui/view/modifier(_:)) +
118+
/// [`ViewModifier`](https://developer.apple.com/documentation/swiftui/viewmodifier) pattern.
119+
///
120+
/// - Note: Useful only when you don't need to reuse the closure.
121+
/// If you do, turn the closure into a proper modifier.
122+
public func modifier<ModifiedContent: View>(
123+
@ViewBuilder _ modifier: (Self) -> ModifiedContent
124+
) -> ModifiedContent {
125+
modifier(self)
118126
}
119127
}

Examples/Demo/Demo/Pages.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct PageOne: View {
1313
} destination: {
1414
PageTwo()
1515
}
16-
.do {
16+
.modifier {
1717
if #available(iOS 16, tvOS 16, *) {
1818
$0.navigationDestination(for: Int.self) { number in
1919
switch number {
@@ -130,9 +130,9 @@ struct PageLink: View {
130130
.fill(Color.blue.opacity(0.8))
131131
#endif
132132
Text(title)
133-
#if !os(tvOS)
133+
#if !os(tvOS)
134134
.foregroundColor(.white)
135-
#endif
135+
#endif
136136
.font(.system(size: 18, weight: .medium, design: .rounded))
137137
}
138138
.frame(maxHeight: 50)
@@ -162,14 +162,14 @@ struct Code<Content: StringProtocol>: View {
162162
.font(.system(size: 14, design: .monospaced))
163163
.background(shape.stroke(Color(white: 0.1).opacity(0.35), lineWidth: 1))
164164
.background(Color(white: 0.94).opacity(0.6).clipShape(shape))
165-
#if !os(tvOS)
166-
.do {
165+
#if !os(tvOS)
166+
.modifier {
167167
if #available(iOS 15, *) {
168168
$0.textSelection(.enabled)
169169
} else {
170170
$0
171171
}
172172
}
173-
#endif
173+
#endif
174174
}
175175
}

Sources/NavigationTransitions/NavigationTransition+SwiftUI.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import SwiftUI
22
@_implementationOnly @_spi(Advanced) import SwiftUIIntrospect
33

44
extension View {
5-
@ViewBuilder
65
public func navigationTransition(
76
_ transition: AnyNavigationTransition,
87
interactivity: AnyNavigationTransition.Interactivity = .default

0 commit comments

Comments
 (0)