dismissalConfirmationDialog

Presents a confirmation dialog upon an attempt to dismiss the window for this view.

View ModifieriOS 27.0+macOS 15.0+

Overloads

2 ways to call compose().dismissalConfirmationDialog(). Each is one SwiftUI overload, picked by the arguments you pass.

React
compose().dismissalConfirmationDialog(
  titleResource: string,
  options: {
    shouldPresent: boolean;
    actions: ReactNode;
  }
)
Swift
@export(implementation) nonisolated func dismissalConfirmationDialog<A>(
    _ titleResource: LocalizedStringResource,
    shouldPresent: Bool,
    @ContentBuilder actions: () -> A
) -> some View
where A : View
3 more Swift overloads share this form
Swift
nonisolated func dismissalConfirmationDialog<A>(
    _ titleKey: LocalizedStringKey,
    shouldPresent: Bool,
    @ContentBuilder actions: () -> A
) -> some View
where A : View
Swift
nonisolated func dismissalConfirmationDialog<A>(
    _ title: Text,
    shouldPresent: Bool,
    @ContentBuilder actions: () -> A
) -> some View
where A : View
Swift
nonisolated func dismissalConfirmationDialog<S, A>(
    _ title: S,
    shouldPresent: Bool,
    @ContentBuilder actions: () -> A
) -> some View
where S : StringProtocol, A : View

Parameters

  • titleResource*string

    Text resource for the localized string that describes the title of the dialog.

  • options.shouldPresent*boolean

    A Boolean value that determines whether to present the dialog upon dismissal.

  • options.actions*ReactNode

    A content builder returning the dialog's actions.

Discussion

On macOS, the dialog will be presented when attempting to dismiss the window for this view, either through a user-initiated dismissal or a programmatic dismiss action. On iOS, the dialog will only be presented for a user-initiated dismissal.

For example, you could present a dialog asking to persist unsaved changes:

struct ComposeMessage: View {
    @State private var message = Message()
```swift

var body: some View {
    MessageEditor(message: $message)
        .dismissalConfirmationDialog(
            "Save This Message As Draft?",
            shouldPresent: message.hasUnsavedChanges
        ) {
            Button("Save") {
                message.save()
            }
            Button("Don't Save", role: .destructive) {
                message.discard()
            }
        } message: {
            Text(
                """
                This message has not been sent and contains\
                unsaved changes.
                """)
        }

}


All actions in the dialog will dismiss the dialog after the
action runs. The default button will be shown with greater prominence.
You can influence the default button by assigning it the
[`KeyboardShortcut.defaultAction`](/docs/values/keyboardshortcut#defaultaction) keyboard shortcut.

The system may reorder the buttons based on their role and prominence.

Dismissal dialogs include a standard cancellation action by default.
If you provide a button with a role of [`ButtonRole.cancel`](/docs/values/buttonrole#cancel), that
button takes the place of the default cancellation action.

The cancellation action will always prevent the dismissal, while other
actions will allow the dismiss to proceed.

On iOS, in addition to the standard cancellation action, the dismissal
dialog also includes a standard close action by default. If you provide
a button with a role of [`ButtonRole.destructive`](/docs/values/buttonrole#destructive), that button takes the
place of the default close action. This action will immediately dismiss the
dialog and the view's associated window.

See also

More in Presentation.