Skip to content

Commit 7b6c34a

Browse files
authored
Fix some docs. (pointfreeco#163)
1 parent b7c9a79 commit 7b6c34a

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ Notice that the trailing closure is handed a binding to the unwrapped state. Thi
4242
handed to the child view, and any changes made by the parent will be reflected in the child, and
4343
vice-versa.
4444

45+
However, this does not compile just yet because `sheet(item:)` requires that the item being
46+
presented conform to `Identifable`, and `Int` does not conform. This library comes with an overload
47+
of `sheet`, called ``SwiftUI/View/sheet(item:id:onDismiss:content:)-1hi9l``, that allows you to
48+
specify the ID of the item being presented:
49+
50+
```swift
51+
var body: some View {
52+
List {
53+
// ...
54+
}
55+
.sheet(item: $destination, id: \.self) { $number in
56+
CounterView(number: $number)
57+
}
58+
}
59+
```
60+
4561
Sometimes it is not optimal to model presentation destinations as optionals. In particular, if a
4662
feature can navigate to multiple, mutually exclusive screens, then an enum is more appropriate.
4763

@@ -65,15 +81,15 @@ var body: some View {
6581
List {
6682
// ...
6783
}
68-
.sheet(item: $destination.counter) { $number in
84+
.sheet(item: $destination.counter, id: \.self) { $number in
6985
CounterView(number: $number)
7086
}
7187
}
7288
```
7389

7490
### Popovers
7591

76-
Popovers work similarly to covers. If the popover's state is represented as an optional you can do
92+
Popovers work similarly to sheets. If the popover's state is represented as an optional you can do
7793
the following:
7894

7995
```swift
@@ -84,7 +100,7 @@ struct ContentView: View {
84100
List {
85101
// ...
86102
}
87-
.popover(item: $destination) { $number in
103+
.popover(item: $destination, id: \.self) { $number in
88104
CounterView(number: $number)
89105
}
90106
}
@@ -107,7 +123,7 @@ struct ContentView: View {
107123
List {
108124
// ...
109125
}
110-
.popover(item: $destination.counter) { $number in
126+
.popover(item: $destination.counter, id: \.self) { $number in
111127
CounterView(number: $number)
112128
}
113129
}
@@ -116,7 +132,7 @@ struct ContentView: View {
116132

117133
### Covers
118134

119-
Full screen covers work similarly to covers and sheets. If the cover's state is represented as an
135+
Full screen covers work similarly to sheets and popovers. If the cover's state is represented as an
120136
optional you can do the following:
121137

122138
```swift
@@ -127,7 +143,7 @@ struct ContentView: View {
127143
List {
128144
// ...
129145
}
130-
.fullscreenCover(item: $destination) { $number in
146+
.fullscreenCover(item: $destination, id: \.self) { $number in
131147
CounterView(number: $number)
132148
}
133149
}
@@ -150,7 +166,7 @@ struct ContentView: View {
150166
List {
151167
// ...
152168
}
153-
.fullscreenCover(item: $destination.counter) { $number in
169+
.fullscreenCover(item: $destination.counter, id: \.self) { $number in
154170
CounterView(number: $number)
155171
}
156172
}

0 commit comments

Comments
 (0)