1
1
#if canImport(SwiftUI)
2
- import SwiftUI
2
+ import SwiftUI
3
3
4
- extension View {
5
- /// Presents a full-screen cover using a binding as a data source for the sheet's content.
6
- ///
7
- /// SwiftUI comes with a `fullScreenCover(item:)` view modifier that is powered by a binding to
8
- /// some hashable state. When this state becomes non-`nil`, it passes an unwrapped value to the
9
- /// content closure. This value, however, is completely static, which prevents the sheet from
10
- /// modifying it.
11
- ///
12
- /// This overload differs in that it passes a _binding_ to the unwrapped value, instead. This
13
- /// gives the sheet the ability to write changes back to its source of truth.
14
- ///
15
- /// Also unlike `fullScreenCover(item:)`, the binding's value does _not_ need to be hashable.
16
- ///
17
- /// ```swift
18
- /// struct TimelineView: View {
19
- /// @State var draft: Post?
20
- ///
21
- /// var body: Body {
22
- /// Button("Compose") {
23
- /// self.draft = Post()
24
- /// }
25
- /// .fullScreenCover(unwrapping: self.$draft) { $draft in
26
- /// ComposeView(post: $draft, onSubmit: { ... })
27
- /// }
28
- /// }
29
- /// }
30
- ///
31
- /// struct ComposeView: View {
32
- /// @Binding var post: Post
33
- /// var body: some View { ... }
34
- /// }
35
- /// ```
36
- ///
37
- /// - Parameters:
38
- /// - 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
43
- /// dismissed.
44
- /// - onDismiss: The closure to execute when dismissing the sheet.
45
- /// - content: A closure returning the content of the sheet.
46
- @available ( iOS 14 , tvOS 14 , watchOS 7 , * )
47
- @available ( macOS, unavailable)
48
- public func fullScreenCover< Value, Content> (
49
- unwrapping value: Binding < Value ? > ,
50
- onDismiss: ( ( ) -> Void ) ? = nil ,
51
- @ViewBuilder content: @escaping ( Binding < Value > ) -> Content
52
- ) -> some View
53
- where Content: View {
54
- self . fullScreenCover (
55
- isPresented: value. isPresent ( ) ,
56
- onDismiss: onDismiss
57
- ) {
58
- Binding ( unwrapping: value) . map ( content)
4
+ extension View {
5
+ /// Presents a full-screen cover using a binding as a data source for the sheet's content.
6
+ ///
7
+ /// SwiftUI comes with a `fullScreenCover(item:)` view modifier that is powered by a binding to
8
+ /// some hashable state. When this state becomes non-`nil`, it passes an unwrapped value to the
9
+ /// content closure. This value, however, is completely static, which prevents the sheet from
10
+ /// modifying it.
11
+ ///
12
+ /// This overload differs in that it passes a _binding_ to the unwrapped value, instead. This
13
+ /// gives the sheet the ability to write changes back to its source of truth.
14
+ ///
15
+ /// Also unlike `fullScreenCover(item:)`, the binding's value does _not_ need to be hashable.
16
+ ///
17
+ /// ```swift
18
+ /// struct TimelineView: View {
19
+ /// @State var draft: Post?
20
+ ///
21
+ /// var body: Body {
22
+ /// Button("Compose") {
23
+ /// self.draft = Post()
24
+ /// }
25
+ /// .fullScreenCover(unwrapping: self.$draft) { $draft in
26
+ /// ComposeView(post: $draft, onSubmit: { ... })
27
+ /// }
28
+ /// }
29
+ /// }
30
+ ///
31
+ /// struct ComposeView: View {
32
+ /// @Binding var post: Post
33
+ /// var body: some View { ... }
34
+ /// }
35
+ /// ```
36
+ ///
37
+ /// - Parameters:
38
+ /// - 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
43
+ /// dismissed.
44
+ /// - onDismiss: The closure to execute when dismissing the sheet.
45
+ /// - content: A closure returning the content of the sheet.
46
+ @available ( iOS 14 , tvOS 14 , watchOS 7 , * )
47
+ @available ( macOS, unavailable)
48
+ public func fullScreenCover< Value, Content> (
49
+ unwrapping value: Binding < Value ? > ,
50
+ onDismiss: ( ( ) -> Void ) ? = nil ,
51
+ @ViewBuilder content: @escaping ( Binding < Value > ) -> Content
52
+ ) -> some View
53
+ where Content: View {
54
+ self . fullScreenCover (
55
+ isPresented: value. isPresent ( ) ,
56
+ onDismiss: onDismiss
57
+ ) {
58
+ Binding ( unwrapping: value) . map ( content)
59
+ }
59
60
}
60
- }
61
61
62
- /// Presents a full-screen cover using a binding and case path as a data source for the sheet's
63
- /// content.
64
- ///
65
- /// A version of `fullScreenCover(unwrapping:)` that works with enum state.
66
- ///
67
- /// - Parameters:
68
- /// - enum: A binding to an optional enum that holds the source of truth for the sheet at a
69
- /// particular case. When `enum` is non-`nil`, and `casePath` successfully extracts a value, a
70
- /// non-optional binding to the value is passed to the `content` closure. You use this binding
71
- /// to produce content that the system presents to the user in a sheet. Changes made to the
72
- /// sheet's binding will be reflected back in the source of truth. Likewise, changes to `enum`
73
- /// at the given case are instantly reflected in the sheet. If `enum` becomes `nil`, or
74
- /// becomes a case other than the one identified by `casePath`, the sheet is dismissed.
75
- /// - casePath: A case path that identifies a case of `enum` that holds a source of truth for
76
- /// the sheet.
77
- /// - onDismiss: The closure to execute when dismissing the sheet.
78
- /// - content: A closure returning the content of the sheet.
79
- @available ( iOS 14 , tvOS 14 , watchOS 7 , * )
80
- @available ( macOS, unavailable)
81
- public func fullScreenCover< Enum, Case, Content> (
82
- unwrapping enum: Binding < Enum ? > ,
83
- case casePath: CasePath < Enum , Case > ,
84
- onDismiss: ( ( ) -> Void ) ? = nil ,
85
- @ViewBuilder content: @escaping ( Binding < Case > ) -> Content
86
- ) -> some View
87
- where Content: View {
88
- self . fullScreenCover ( unwrapping: `enum`. case ( casePath) , onDismiss: onDismiss, content: content)
62
+ /// Presents a full-screen cover using a binding and case path as a data source for the sheet's
63
+ /// content.
64
+ ///
65
+ /// A version of `fullScreenCover(unwrapping:)` that works with enum state.
66
+ ///
67
+ /// - Parameters:
68
+ /// - enum: A binding to an optional enum that holds the source of truth for the sheet at a
69
+ /// particular case. When `enum` is non-`nil`, and `casePath` successfully extracts a value, a
70
+ /// non-optional binding to the value is passed to the `content` closure. You use this binding
71
+ /// to produce content that the system presents to the user in a sheet. Changes made to the
72
+ /// sheet's binding will be reflected back in the source of truth. Likewise, changes to `enum`
73
+ /// at the given case are instantly reflected in the sheet. If `enum` becomes `nil`, or
74
+ /// becomes a case other than the one identified by `casePath`, the sheet is dismissed.
75
+ /// - casePath: A case path that identifies a case of `enum` that holds a source of truth for
76
+ /// the sheet.
77
+ /// - onDismiss: The closure to execute when dismissing the sheet.
78
+ /// - content: A closure returning the content of the sheet.
79
+ @available ( iOS 14 , tvOS 14 , watchOS 7 , * )
80
+ @available ( macOS, unavailable)
81
+ public func fullScreenCover< Enum, Case, Content> (
82
+ unwrapping enum: Binding < Enum ? > ,
83
+ case casePath: CasePath < Enum , Case > ,
84
+ onDismiss: ( ( ) -> Void ) ? = nil ,
85
+ @ViewBuilder content: @escaping ( Binding < Case > ) -> Content
86
+ ) -> some View
87
+ where Content: View {
88
+ self . fullScreenCover (
89
+ unwrapping: `enum`. case ( casePath) , onDismiss: onDismiss, content: content)
90
+ }
89
91
}
90
- }
91
- #endif // canImport(SwiftUI)
92
+ #endif // canImport(SwiftUI)
0 commit comments