|
1 | 1 | #if canImport(SwiftUI)
|
2 | 2 | import SwiftUI
|
3 | 3 |
|
| 4 | + @available(iOS 14, tvOS 14, watchOS 7, *) |
| 5 | + @available(macOS, unavailable) |
4 | 6 | extension View {
|
| 7 | + /// Presents a full-screen cover using a binding as a data source for the sheet's content based |
| 8 | + /// on the identity of the underlying item. |
| 9 | + /// |
| 10 | + /// - Parameters: |
| 11 | + /// - item: A binding to an optional source of truth for the sheet. When `item` is non-`nil`, |
| 12 | + /// the system passes the item's content to the modifier's closure. You display this content |
| 13 | + /// in a sheet that you create that the system displays to the user. If `item` changes, the |
| 14 | + /// system dismisses the sheet and replaces it with a new one using the same process. |
| 15 | + /// - id: The key path to the provided item's identifier. |
| 16 | + /// - onDismiss: The closure to execute when dismissing the sheet. |
| 17 | + /// - content: A closure returning the content of the sheet. |
| 18 | + public func fullScreenCover<Item, ID: Hashable, Content: View>( |
| 19 | + item: Binding<Item?>, |
| 20 | + id: KeyPath<Item, ID>, |
| 21 | + onDismiss: (() -> Void)? = nil, |
| 22 | + @ViewBuilder content: @escaping (Item) -> Content |
| 23 | + ) -> some View { |
| 24 | + self.fullScreenCover(item: item[id: id], onDismiss: onDismiss) { _ in |
| 25 | + item.wrappedValue.map(content) |
| 26 | + } |
| 27 | + } |
| 28 | + |
5 | 29 | /// Presents a full-screen cover using a binding as a data source for the sheet's content.
|
6 | 30 | ///
|
7 | 31 | /// SwiftUI comes with a `fullScreenCover(item:)` view modifier that is powered by a binding to
|
|
36 | 60 | ///
|
37 | 61 | /// - Parameters:
|
38 | 62 | /// - value: A binding to a source of truth for the sheet. When `value` is non-`nil`, a
|
39 |
| - /// non-optional binding to the value is passed to the `content` closure. You use this binding |
40 |
| - /// to produce content that the system presents to the user in a sheet. Changes made to the |
41 |
| - /// sheet's binding will be reflected back in the source of truth. Likewise, changes to |
42 |
| - /// `value` are instantly reflected in the sheet. If `value` becomes `nil`, the sheet is |
| 63 | + /// non-optional binding to the value is passed to the `content` closure. You use this |
| 64 | + /// binding to produce content that the system presents to the user in a sheet. Changes made |
| 65 | + /// to the sheet's binding will be reflected back in the source of truth. Likewise, changes |
| 66 | + /// to `value` are instantly reflected in the sheet. If `value` becomes `nil`, the sheet is |
43 | 67 | /// dismissed.
|
44 | 68 | /// - onDismiss: The closure to execute when dismissing the sheet.
|
45 | 69 | /// - content: A closure returning the content of the sheet.
|
46 |
| - @available(iOS 14, tvOS 14, watchOS 7, *) |
47 |
| - @available(macOS, unavailable) |
48 | 70 | public func fullScreenCover<Value, Content>(
|
49 | 71 | unwrapping value: Binding<Value?>,
|
50 | 72 | onDismiss: (() -> Void)? = nil,
|
|
0 commit comments