@@ -121,12 +121,12 @@ extension View {
121
121
/// to populate the fields of a dialog that the system displays to the user. When the user
122
122
/// presses or taps one of the dialog's actions, the system sets this value to `nil` and
123
123
/// dismisses the dialog, and the action is fed to the `action` closure.
124
- /// - action : A closure that is called with an action from a particular dialog button when
124
+ /// - handler : A closure that is called with an action from a particular dialog button when
125
125
/// tapped.
126
126
@available ( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * )
127
127
public func confirmationDialog< Value> (
128
128
unwrapping value: Binding < ConfirmationDialogState < Value > ? > ,
129
- action: @escaping ( Value ) -> Void = { ( _: Never ) in fatalError ( ) }
129
+ action handler : @escaping ( Value ) async -> Void = { ( _: Void ) async in }
130
130
) -> some View {
131
131
self . confirmationDialog (
132
132
value. wrappedValue. flatMap { Text ( $0. title) } ?? Text ( " " ) ,
@@ -135,7 +135,11 @@ extension View {
135
135
presenting: value. wrappedValue,
136
136
actions: {
137
137
ForEach ( $0. buttons) {
138
- Button ( $0, action: action)
138
+ Button ( $0) { action in
139
+ Task {
140
+ await handler ( action)
141
+ }
142
+ }
139
143
}
140
144
} ,
141
145
message: { $0. message. map { Text ( $0) } }
@@ -155,24 +159,24 @@ extension View {
155
159
/// When the user presses or taps one of the dialog's actions, the system sets this value to
156
160
/// `nil` and dismisses the dialog, and the action is fed to the `action` closure.
157
161
/// - casePath: A case path that identifies a particular case that holds dialog state.
158
- /// - action : A closure that is called with an action from a particular dialog button when
162
+ /// - handler : A closure that is called with an action from a particular dialog button when
159
163
/// tapped.
160
164
@available ( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * )
161
165
public func confirmationDialog< Enum, Value> (
162
166
unwrapping `enum`: Binding < Enum ? > ,
163
167
case casePath: CasePath < Enum , ConfirmationDialogState < Value > > ,
164
- action: @escaping ( Value ) -> Void = { ( _: Never ) in fatalError ( ) }
168
+ action handler : @escaping ( Value ) async -> Void = { ( _: Void ) async in }
165
169
) -> some View {
166
170
self . confirmationDialog (
167
171
unwrapping: `enum`. case ( casePath) ,
168
- action: action
172
+ action: handler
169
173
)
170
174
}
171
175
#else
172
176
@available ( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * )
173
177
public func confirmationDialog< Value> (
174
178
unwrapping value: Binding < ConfirmationDialogState < Value > ? > ,
175
- action: @escaping ( Value ) -> Void
179
+ action handler : @escaping ( Value ) async -> Void
176
180
) -> some View {
177
181
self . confirmationDialog (
178
182
value. wrappedValue. flatMap { Text ( $0. title) } ?? Text ( " " ) ,
@@ -181,12 +185,17 @@ extension View {
181
185
presenting: value. wrappedValue,
182
186
actions: {
183
187
ForEach ( $0. buttons) {
184
- Button ( $0, action: action)
188
+ Button ( $0) { action in
189
+ Task {
190
+ await handler ( action)
191
+ }
192
+ }
185
193
}
186
194
} ,
187
195
message: { $0. message. map { Text ( $0) } }
188
196
)
189
197
}
198
+
190
199
@available ( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * )
191
200
public func confirmationDialog(
192
201
unwrapping value: Binding < ConfirmationDialogState < Never > ? >
@@ -196,17 +205,19 @@ extension View {
196
205
action: { ( _: Never ) in fatalError ( ) }
197
206
)
198
207
}
208
+
199
209
@available ( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * )
200
210
public func confirmationDialog< Enum, Value> (
201
211
unwrapping `enum`: Binding < Enum ? > ,
202
212
case casePath: CasePath < Enum , ConfirmationDialogState < Value > > ,
203
- action: @escaping ( Value ) -> Void
213
+ action handler : @escaping ( Value ) async -> Void
204
214
) -> some View {
205
215
self . confirmationDialog (
206
216
unwrapping: `enum`. case ( casePath) ,
207
- action: action
217
+ action: handler
208
218
)
209
219
}
220
+
210
221
@available ( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * )
211
222
public func confirmationDialog< Enum> (
212
223
unwrapping `enum`: Binding < Enum ? > ,
0 commit comments