Skip to content

Commit 7ab04c6

Browse files
authored
Fix DocC and update NavigationLink(unwrapping:) (pointfreeco#158)
* Fix DocC and update `NavigationLink(unwrapping:)` * wip * wip
1 parent 7f16357 commit 7ab04c6

File tree

10 files changed

+57
-35
lines changed

10 files changed

+57
-35
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ non-`nil`. You can construct a `NavigationLink` that will activate when that sta
2525
non-`nil`, and will deactivate when the state becomes `nil`:
2626

2727
```swift
28-
NavigationLink(unwrapping: $destination) { isActive in
28+
NavigationLink(item: $destination) { isActive in
2929
destination = isActive ? 42 : nil
3030
} destination: { $number in
3131
CounterView(number: $number)
@@ -81,12 +81,12 @@ one of these destinations:
8181
```
8282

8383
With this set up you can make use of the
84-
``SwiftUI/NavigationLink/init(unwrapping:onNavigate:destination:label:)`` initializer on
84+
``SwiftUI/NavigationLink/init(item:onNavigate:destination:label:)`` initializer on
8585
`NavigationLink` in order to specify a binding to the optional destination, and further specify
8686
which case of the enum you want driving navigation:
8787

8888
```swift
89-
NavigationLink(unwrapping: $destination.counter) { isActive in
89+
NavigationLink(item: $destination.counter) { isActive in
9090
destination = isActive ? .counter(42) : nil
9191
} destination: { $number in
9292
CounterView(number: $number)
@@ -95,15 +95,15 @@ NavigationLink(unwrapping: $destination.counter) { isActive in
9595
}
9696
```
9797

98-
And similarly for ``SwiftUI/View/navigationDestination(unwrapping:destination:)``:
98+
And similarly for ``SwiftUI/View/navigationDestination(item:destination:)``:
9999

100100
```swift
101101
Button {
102102
destination = .counter(42)
103103
} label: {
104104
Text("Go to counter")
105105
}
106-
.navigationDestination(unwrapping: $model.destination.counter) { $number in
106+
.navigationDestination(item: $model.destination.counter) { $number in
107107
CounterView(number: $number)
108108
}
109109
```
@@ -113,7 +113,7 @@ Button {
113113
### Navigation views and modifiers
114114

115115
- ``SwiftUI/View/navigationDestination(item:destination:)``
116-
- ``SwiftUI/NavigationLink/init(unwrapping:onNavigate:destination:label:)``
116+
- ``SwiftUI/NavigationLink/init(item:onNavigate:destination:label:)``
117117

118118
### Supporting types
119119

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ later. If you must support iOS 15 and earlier, you can use the following initial
266266
`NavigationLink`, which also has a very similar API to the above:
267267

268268
```swift
269-
NavigationLink(unwrapping: $model.destination.edit) { isActive in
269+
NavigationLink(item: $model.destination.edit) { isActive in
270270
model.setEditIsActive(isActive)
271271
} destination: { $item in
272272
EditItemView(item: $item)

Sources/SwiftUINavigation/Documentation.docc/Extensions/Deprecations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ instead.
1313

1414
- ``IfLet``
1515
- ``IfCaseLet``
16+
- ``SwiftUI/NavigationLink/init(unwrapping:onNavigate:destination:label:)``
1617
- ``SwiftUI/NavigationLink/init(unwrapping:case:onNavigate:destination:label:)``
1718
- ``SwiftUI/NavigationLink/init(unwrapping:destination:onNavigate:label:)``
1819
- ``SwiftUI/NavigationLink/init(unwrapping:case:destination:onNavigate:label:)``

Sources/SwiftUINavigation/FullScreenCover.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060

6161
/// Presents a full-screen cover using a binding as a data source for the sheet's content.
6262
///
63-
/// A version of ``fullScreenCover(item:id:onDismiss:content:)-14to1`` that takes an
64-
/// identifiable item.
63+
/// A version of ``SwiftUI/View/fullScreenCover(item:id:onDismiss:content:)-14to1`` that takes
64+
/// an identifiable item.
6565
///
6666
/// - Parameters:
6767
/// - item: A binding to an optional source of truth for the sheet. When `item` is non-`nil`,
@@ -82,8 +82,8 @@
8282

8383
/// Presents a full-screen cover using a binding as a data source for the sheet's content.
8484
///
85-
/// A version of ``fullScreenCover(item:id:onDismiss:content:)-14to1`` that is passed an item
86-
/// and not a binding to an item.
85+
/// A version of ``SwiftUI/View/fullScreenCover(item:id:onDismiss:content:)-14to1`` that is
86+
/// passed an item and not a binding to an item.
8787
///
8888
/// - Parameters:
8989
/// - item: A binding to an optional source of truth for the sheet. When `item` is non-`nil`,

Sources/SwiftUINavigation/Internal/Deprecations.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@
118118
}
119119
}
120120

121+
@available(iOS, introduced: 13, deprecated: 16)
122+
@available(macOS, introduced: 10.15, deprecated: 13)
123+
@available(tvOS, introduced: 13, deprecated: 16)
124+
@available(watchOS, introduced: 6, deprecated: 9)
125+
extension NavigationLink {
126+
@available(*, deprecated, renamed: "init(item:onNavigate:destination:label:)")
127+
public init<Value, WrappedDestination>(
128+
unwrapping value: Binding<Value?>,
129+
onNavigate: @escaping (_ isActive: Bool) -> Void,
130+
@ViewBuilder destination: @escaping (Binding<Value>) -> WrappedDestination,
131+
@ViewBuilder label: () -> Label
132+
) where Destination == WrappedDestination? {
133+
self.init(
134+
destination: Binding(unwrapping: value).map(destination),
135+
isActive: value.isPresent().didSet(onNavigate),
136+
label: label
137+
)
138+
}
139+
}
140+
121141
// NB: Deprecated after 1.2.1
122142

123143
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *)
@@ -681,7 +701,7 @@
681701
@ViewBuilder label: () -> Label
682702
) where Destination == WrappedDestination? {
683703
self.init(
684-
unwrapping: `enum`.case(casePath),
704+
item: `enum`.case(casePath),
685705
onNavigate: onNavigate,
686706
destination: destination,
687707
label: label

Sources/SwiftUINavigation/NavigationDestination.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/// Button("Compose") {
1818
/// self.draft = Post()
1919
/// }
20-
/// .navigationDestination(unwrapping: $draft) { $draft in
20+
/// .navigationDestination(item: $draft) { $draft in
2121
/// ComposeView(post: $draft, onSubmit: { ... })
2222
/// }
2323
/// }

Sources/SwiftUINavigation/NavigationLink.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
///
88
/// > Note: This interface is deprecated to match the availability of the corresponding SwiftUI
99
/// > API. If you are targeting iOS 16 or later, use
10-
/// > ``SwiftUI/View/navigationDestination(unwrapping:destination:)``, instead.
10+
/// > ``SwiftUI/View/navigationDestination(item:destination:)``, instead.
1111
///
1212
/// This allows you to drive navigation to a destination from an optional value. When the
1313
/// optional value becomes non-`nil` a binding to an honest value is derived and passed to the
@@ -21,8 +21,8 @@
2121
///
2222
/// var body: some View {
2323
/// ForEach(self.posts) { post in
24-
/// NavigationLink(unwrapping: self.$postToEdit) { isActive in
25-
/// self.postToEdit = isActive ? post : nil
24+
/// NavigationLink(item: $postToEdit) { isActive in
25+
/// postToEdit = isActive ? post : nil
2626
/// } destination: { $draft in
2727
/// EditPostView(post: $draft)
2828
/// } label: {
@@ -39,30 +39,30 @@
3939
/// ```
4040
///
4141
/// - Parameters:
42-
/// - value: A binding to an optional source of truth for the destination. When `value` is
42+
/// - item: A binding to an optional source of truth for the destination. When `item` is
4343
/// non-`nil`, a non-optional binding to the value is passed to the `destination` closure.
4444
/// The destination can use this binding to produce its content and write changes back to
45-
/// the source of truth. Upstream changes to `value` will also be instantly reflected in the
46-
/// destination. If `value` becomes `nil`, the destination is dismissed.
45+
/// the source of truth. Upstream changes to `item` will also be instantly reflected in the
46+
/// destination. If `item` becomes `nil`, the destination is dismissed.
4747
/// - onNavigate: A closure that executes when the link becomes active or inactive with a
4848
/// boolean that describes if the link was activated or not. Use this closure to populate
4949
/// the source of truth when it is passed a value of `true`. When passed `false`, the system
50-
/// will automatically write `nil` to `value`.
50+
/// will automatically write `nil` to `item`.
5151
/// - destination: A view for the navigation link to present.
5252
/// - label: A view builder to produce a label describing the `destination` to present.
5353
@available(iOS, introduced: 13, deprecated: 16)
5454
@available(macOS, introduced: 10.15, deprecated: 13)
5555
@available(tvOS, introduced: 13, deprecated: 16)
5656
@available(watchOS, introduced: 6, deprecated: 9)
57-
public init<Value, WrappedDestination>(
58-
unwrapping value: Binding<Value?>,
57+
public init<Item, WrappedDestination>(
58+
item: Binding<Item?>,
5959
onNavigate: @escaping (_ isActive: Bool) -> Void,
60-
@ViewBuilder destination: @escaping (Binding<Value>) -> WrappedDestination,
60+
@ViewBuilder destination: @escaping (Binding<Item>) -> WrappedDestination,
6161
@ViewBuilder label: () -> Label
6262
) where Destination == WrappedDestination? {
6363
self.init(
64-
destination: Binding(unwrapping: value).map(destination),
65-
isActive: value.isPresent().didSet(onNavigate),
64+
destination: Binding(unwrapping: item).map(destination),
65+
isActive: item.isPresent().didSet(onNavigate),
6666
label: label
6767
)
6868
}

Sources/SwiftUINavigation/Popover.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/// Button("Compose") {
2525
/// self.draft = Post()
2626
/// }
27-
/// .popover(unwrapping: $draft) { $draft in
27+
/// .popover(item: $draft) { $draft in
2828
/// ComposeView(post: $draft, onSubmit: { ... })
2929
/// }
3030
/// }
@@ -70,8 +70,8 @@
7070

7171
/// Presents a full-screen cover using a binding as a data source for the sheet's content.
7272
///
73-
/// A version of ``fullScreenCover(item:id:onDismiss:content:)-14to1`` that takes an
74-
/// identifiable item.
73+
/// A version of ``SwiftUI/View/fullScreenCover(item:id:onDismiss:content:)-14to1`` that takes
74+
/// an identifiable item.
7575
///
7676
/// - Parameters:
7777
/// - item: A binding to an optional source of truth for the popover. When `item` is
@@ -106,8 +106,8 @@
106106
/// Presents a popover using a binding as a data source for the sheet's content based on the
107107
/// identity of the underlying item.
108108
///
109-
/// A version of ``popover(item:id:attachmentAnchor:arrowEdge:content:)-3un96`` that is passed
110-
/// an item and not a binding to an item.
109+
/// A version of ``SwiftUI/View/popover(item:id:attachmentAnchor:arrowEdge:content:)-3un96``
110+
/// that is passed an item and not a binding to an item.
111111
///
112112
/// - Parameters:
113113
/// - item: A binding to an optional source of truth for the popover. When `item` is

Sources/SwiftUINavigation/Sheet.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464

6565
/// Presents a sheet using a binding as a data source for the sheet's content.
6666
///
67-
/// A version of ``sheet(item:id:onDismiss:content:)-1hi9l`` that takes an identifiable item.
67+
/// A version of ``SwiftUI/View/sheet(item:id:onDismiss:content:)-1hi9l`` that takes an
68+
/// identifiable item.
6869
///
6970
/// - Parameters:
7071
/// - item: A binding to an optional source of truth for the sheet. When `item` is non-`nil`,
@@ -85,8 +86,8 @@
8586

8687
/// Presents a sheet using a binding as a data source for the sheet's content.
8788
///
88-
/// A version of ``sheet(item:id:onDismiss:content:)-1hi9l`` that is passed an item and not a
89-
/// binding to an item.
89+
/// A version of ``SwiftUI/View/sheet(item:id:onDismiss:content:)-1hi9l`` that is passed an item
90+
/// and not a binding to an item.
9091
///
9192
/// - Parameters:
9293
/// - item: A binding to an optional source of truth for the sheet. When `item` is non-`nil`,

Sources/SwiftUINavigationCore/ConfirmationDialogState.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
/// }
7171
/// ```
7272
///
73-
/// And in your view you can use the `.confirmationDialog(unwrapping:action:)` view modifier to
73+
/// And in your view you can use the `.confirmationDialog(_:action:)` view modifier to
7474
/// present the dialog:
7575
///
7676
/// ```swift
@@ -83,7 +83,7 @@
8383
/// self.model.infoButtonTapped()
8484
/// }
8585
/// }
86-
/// .confirmationDialog(unwrapping: self.$model.dialog) { action in
86+
/// .confirmationDialog($model.dialog) { action in
8787
/// self.model.dialogButtonTapped(action)
8888
/// }
8989
/// }

0 commit comments

Comments
 (0)