Skip to content

Commit 47dd574

Browse files
authored
Scope navigationDestination bind workaround (pointfreeco#93)
* Scope `navigationDestination` bind workaround * Update NavigationDestination.swift * wip
1 parent 1bc2bc9 commit 47dd574

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Sources/SwiftUINavigation/NavigationDestination.swift

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,23 @@
3838
/// the source of truth. Likewise, changes to `value` are instantly reflected in the
3939
/// destination. If `value` becomes `nil`, the destination is popped.
4040
/// - destination: A closure returning the content of the destination.
41+
@ViewBuilder
4142
public func navigationDestination<Value, Destination: View>(
4243
unwrapping value: Binding<Value?>,
4344
@ViewBuilder destination: (Binding<Value>) -> Destination
4445
) -> some View {
45-
self.modifier(
46-
_NavigationDestination(
47-
isPresented: value.isPresent(),
48-
destination: Binding(unwrapping: value).map(destination)
46+
if requiresBindWorkaround {
47+
self.modifier(
48+
_NavigationDestinationBindWorkaround(
49+
isPresented: value.isPresent(),
50+
destination: Binding(unwrapping: value).map(destination)
51+
)
4952
)
50-
)
53+
} else {
54+
self.navigationDestination(isPresented: value.isPresent()) {
55+
Binding(unwrapping: value).map(destination)
56+
}
57+
}
5158
}
5259

5360
/// Pushes a view onto a `NavigationStack` using a binding and case path as a data source for
@@ -79,7 +86,7 @@
7986
// NB: This view modifier works around a bug in SwiftUI's built-in modifier:
8087
// https://gist.github.com/mbrandonw/f8b94957031160336cac6898a919cbb7#file-fb11056434-md
8188
@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
82-
private struct _NavigationDestination<Destination: View>: ViewModifier {
89+
private struct _NavigationDestinationBindWorkaround<Destination: View>: ViewModifier {
8390
@Binding var isPresented: Bool
8491
let destination: Destination
8592

@@ -91,4 +98,10 @@
9198
.bind(self.$isPresented, to: self.$isPresentedState)
9299
}
93100
}
101+
102+
private let requiresBindWorkaround = {
103+
guard #available(iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4, *)
104+
else { return true }
105+
return false
106+
}()
94107
#endif

0 commit comments

Comments
 (0)