import SwiftUI @available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) extension View { /// Displays a dialog when then store's state becomes non-`nil`, and dismisses it when it becomes /// `nil`. /// /// - Parameters: /// - store: A store that is focused on ``PresentationState`` and ``PresentationAction`` for a /// dialog. public func confirmationDialog( store: Store< PresentationState>, PresentationAction > ) -> some View { self.confirmationDialog(store: store, state: { $0 }, action: { $0 }) } /// Displays a dialog when then store's state becomes non-`nil`, and dismisses it when it becomes /// `nil`. /// /// - Parameters: /// - store: A store that is focused on ``PresentationState`` and ``PresentationAction`` for a /// dialog. /// - toDestinationState: A transformation to extract dialog state from the presentation state. /// - fromDestinationAction: A transformation to embed dialog actions into the presentation /// action. public func confirmationDialog( store: Store, PresentationAction>, state toDestinationState: @escaping (_ state: State) -> ConfirmationDialogState?, action fromDestinationAction: @escaping (_ confirmationDialogAction: ButtonAction) -> Action ) -> some View { self.presentation( store: store, state: toDestinationState, action: fromDestinationAction ) { `self`, $isPresented, destination in let confirmationDialogState = store.withState { $0.wrappedValue.flatMap(toDestinationState) } self.confirmationDialog( (confirmationDialogState?.title).map(Text.init) ?? Text(verbatim: ""), isPresented: $isPresented, titleVisibility: (confirmationDialogState?.titleVisibility).map(Visibility.init) ?? .automatic, presenting: confirmationDialogState, actions: { confirmationDialogState in ForEach(confirmationDialogState.buttons) { button in Button(role: button.role.map(ButtonRole.init)) { switch button.action.type { case let .send(action): if let action = action { store.send(.presented(fromDestinationAction(action))) } case let .animatedSend(action, animation): if let action = action { store.send(.presented(fromDestinationAction(action)), animation: animation) } } } label: { Text(button.label) } } }, message: { $0.message.map(Text.init) } ) } } }