Skip to content

Commit 2ec6c3a

Browse files
authored
Add iOS 16-compatible navigationDestination(item:) to core (pointfreeco#148)
* Add iOS 16-compatible `navigationDestination(item:)` * wip
1 parent 35526c2 commit 2ec6c3a

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

Sources/SwiftUINavigation/Documentation.docc/Articles/Bindings.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ struct SignInView: View {
7878

7979
### Binding transformations
8080

81-
- ``SwiftUI/Binding/isPresent()``
8281
- ``SwiftUI/Binding/removeDuplicates()``
8382
- ``SwiftUI/Binding/removeDuplicates(by:)``
8483

Sources/SwiftUINavigationCore/Documentation.docc/SwiftUINavigationCore.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ``SwiftUINavigationCore``
22

3-
A few core types included in SwiftUI Navigation.
3+
A few core types and modifiers included in SwiftUI Navigation.
44

55
## Topics
66

@@ -10,3 +10,19 @@ A few core types included in SwiftUI Navigation.
1010
- ``AlertState``
1111
- ``ConfirmationDialogState``
1212
- ``ButtonState``
13+
14+
### Alert and dialog modifiers
15+
16+
- ``SwiftUI/View/alert(item:title:actions:message:)``
17+
- ``SwiftUI/View/alert(item:title:actions:)``
18+
- ``SwiftUI/View/confirmationDialog(item:titleVisibility:title:actions:message:)``
19+
- ``SwiftUI/View/confirmationDialog(item:titleVisibility:title:actions:)``
20+
21+
### Bindings
22+
23+
- ``SwiftUI/Binding/isPresent()``
24+
- ``SwiftUI/View/bind(_:to:)``
25+
26+
### Navigation
27+
28+
- ``SwiftUI/View/navigationDestination(item:destination:)``
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#if canImport(SwiftUI)
2+
import SwiftUI
3+
4+
@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
5+
extension View {
6+
/// Associates a destination view with a bound value for use within a navigation stack or
7+
/// navigation split view.
8+
///
9+
/// See `SwiftUI.View.navigationDestination(item:destination:)` for more information.
10+
///
11+
/// - Parameters:
12+
/// - item: A binding to the data presented, or `nil` if nothing is currently presented.
13+
/// - destination: A view builder that defines a view to display when `item` is not `nil`.
14+
public func navigationDestination<D, C: View>(
15+
item: Binding<D?>,
16+
@ViewBuilder destination: @escaping (D) -> C
17+
) -> some View {
18+
navigationDestination(isPresented: item.isPresent()) {
19+
if let item = item.wrappedValue {
20+
destination(item)
21+
}
22+
}
23+
}
24+
}
25+
#endif // canImport(SwiftUI)

0 commit comments

Comments
 (0)