@@ -231,36 +231,76 @@ extension View {
231
231
@available ( macOS 12 , * )
232
232
@available ( tvOS 13 , * )
233
233
@available ( watchOS 6 , * )
234
- public func confirmationDialog< Action> (
234
+ @ ViewBuilder public func confirmationDialog< Action> (
235
235
_ store: Store < ConfirmationDialogState < Action > ? , Action > ,
236
236
dismiss: Action
237
237
) -> some View {
238
-
239
- WithViewStore ( store, removeDuplicates: { $0? . id == $1? . id } ) { viewStore in
240
- #if compiler(>=5.5)
241
- if #available( iOS 15 , tvOS 15 , watchOS 8 , * ) {
242
- self . confirmationDialog (
243
- ( viewStore. state? . title) . map { Text ( $0) } ?? Text ( " " ) ,
244
- isPresented: viewStore. binding ( send: dismiss) . isPresent ( ) ,
245
- titleVisibility: viewStore. state? . titleVisibility. toSwiftUI ?? . automatic,
246
- presenting: viewStore. state,
247
- actions: { $0. toSwiftUIActions ( send: viewStore. send) } ,
248
- message: { $0. message. map { Text ( $0) } }
238
+ #if compiler(>=5.5)
239
+ if #available( iOS 15 , tvOS 15 , watchOS 8 , * ) {
240
+ self . modifier (
241
+ NewConfirmationDialogModifier (
242
+ viewStore: ViewStore ( store, removeDuplicates: { $0? . id == $1? . id } ) ,
243
+ dismiss: dismiss
249
244
)
250
- } else {
251
- #if !os(macOS)
252
- self . actionSheet ( item: viewStore. binding ( send: dismiss) ) { state in
253
- state. toSwiftUIActionSheet ( send: viewStore. send)
254
- }
255
- #endif
256
- }
257
- #elseif !os(macOS)
258
- self . actionSheet ( item: viewStore. binding ( send: dismiss) ) { state in
259
- state. toSwiftUIActionSheet ( send: viewStore. send)
260
- }
261
- #endif
245
+ )
246
+ } else {
247
+ #if !os(macOS)
248
+ self . modifier (
249
+ OldConfirmationDialogModifier (
250
+ viewStore: ViewStore ( store, removeDuplicates: { $0? . id == $1? . id } ) ,
251
+ dismiss: dismiss
252
+ )
253
+ )
254
+ #endif
255
+ }
256
+ #elseif !os(macOS)
257
+ self . modifier (
258
+ OldConfirmationDialogModifier (
259
+ viewStore: ViewStore ( store, removeDuplicates: { $0? . id == $1? . id } ) ,
260
+ dismiss: dismiss
261
+ )
262
+ )
263
+ #endif
264
+ }
265
+ }
266
+
267
+ #if compiler(>=5.5)
268
+ // NB: Workaround for iOS 14 runtime crashes during iOS 15 availability checks.
269
+ @available ( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * )
270
+ private struct NewConfirmationDialogModifier < Action> : ViewModifier {
271
+ @ObservedObject var viewStore : ViewStore < ConfirmationDialogState < Action > ? , Action >
272
+ let dismiss : Action
273
+
274
+ func body( content: Content ) -> some View {
275
+ content. confirmationDialog (
276
+ ( viewStore. state? . title) . map { Text ( $0) } ?? Text ( " " ) ,
277
+ isPresented: viewStore. binding ( send: dismiss) . isPresent ( ) ,
278
+ titleVisibility: viewStore. state? . titleVisibility. toSwiftUI ?? . automatic,
279
+ presenting: viewStore. state,
280
+ actions: { $0. toSwiftUIActions ( send: viewStore. send) } ,
281
+ message: { $0. message. map { Text ( $0) } }
282
+ )
262
283
}
263
284
}
285
+ #endif
286
+
287
+ @available ( iOS 13 , * )
288
+ @available ( macOS 12 , * )
289
+ @available ( tvOS 13 , * )
290
+ @available ( watchOS 6 , * )
291
+ private struct OldConfirmationDialogModifier < Action> : ViewModifier {
292
+ @ObservedObject var viewStore : ViewStore < ConfirmationDialogState < Action > ? , Action >
293
+ let dismiss : Action
294
+
295
+ func body( content: Content ) -> some View {
296
+ #if !os(macOS)
297
+ return content. actionSheet ( item: viewStore. binding ( send: dismiss) ) { state in
298
+ state. toSwiftUIActionSheet ( send: viewStore. send)
299
+ }
300
+ #else
301
+ return EmptyView ( )
302
+ #endif
303
+ }
264
304
}
265
305
266
306
@available ( iOS 13 , * )
0 commit comments