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.
compose().dismissalConfirmationDialog(
titleResource: string,
options: {
shouldPresent: boolean;
actions: ReactNode;
}
)@export(implementation) nonisolated func dismissalConfirmationDialog<A>(
_ titleResource: LocalizedStringResource,
shouldPresent: Bool,
@ContentBuilder actions: () -> A
) -> some View
where A : View3 more Swift overloads share this form
nonisolated func dismissalConfirmationDialog<A>(
_ titleKey: LocalizedStringKey,
shouldPresent: Bool,
@ContentBuilder actions: () -> A
) -> some View
where A : Viewnonisolated func dismissalConfirmationDialog<A>(
_ title: Text,
shouldPresent: Bool,
@ContentBuilder actions: () -> A
) -> some View
where A : Viewnonisolated func dismissalConfirmationDialog<S, A>(
_ title: S,
shouldPresent: Bool,
@ContentBuilder actions: () -> A
) -> some View
where S : StringProtocol, A : ViewParameters
titleResource*stringText resource for the localized string that describes the title of the dialog.
options.shouldPresent*booleanA Boolean value that determines whether to present the dialog upon dismissal.
options.actions*ReactNodeA 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.
- alertPresents an alert when a given condition is true, using a localized string resource for the title.
- confirmationDialogPresents a confirmation dialog when a given condition is true, using a localized string resource for the title.
- contextMenuAdds an item-based context menu to a view.
- dialogIconConfigures the icon used by dialogs within this view.
- dialogSuppressionToggleEnables user suppression of dialogs and alerts presented within self, with a custom suppression message on macOS. Unused on other platforms.
- documentBrowserContextMenuAdds to a DocumentLaunchView actions that accept a list of selected files as their parameter.
- fileDialogBrowserOptionsOn macOS, configures the fileExporter, fileImporter, or fileMover to provide a refined URL search experience: include or exclude hidden files, allow searching by tag, etc.
- fileDialogConfirmationLabelOn macOS, configures the fileExporter, fileImporter, or fileMover with a custom confirmation button label.
- fileDialogCustomizationIDOn macOS, configures the fileExporter, fileImporter, or fileMover to persist and restore the file dialog configuration.
- fileDialogDefaultDirectoryConfigures the fileExporter, fileImporter, or fileMover to open with the specified default directory.
- fileDialogImportsUnresolvedAliasesOn macOS, configures the fileExporter, fileImporter, or fileMover behavior when a user chooses an alias.
- fileDialogMessageOn macOS, configures the fileExporter, fileImporter, or fileMover with a custom message that is presented to the user, similar to a title.