confirmationDialog
Presents a confirmation dialog when a given condition is true, using a localized string resource for the title.
Overloads
6 ways to call compose().confirmationDialog(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().confirmationDialog(
titleResource: string,
options: {
isPresented: Binding<boolean>;
titleVisibility?: SwiftUI.Visibility;
actions: ReactNode;
}
)@export(implementation) nonisolated func confirmationDialog<A>(
_ titleResource: LocalizedStringResource,
isPresented: Binding<Bool>,
titleVisibility: Visibility = .automatic,
@ContentBuilder actions: () -> A
) -> some View
where A : View3 more Swift overloads share this form
nonisolated func confirmationDialog<A>(
_ titleKey: LocalizedStringKey,
isPresented: Binding<Bool>,
titleVisibility: Visibility = .automatic,
@ContentBuilder actions: () -> A
) -> some View
where A : Viewnonisolated func confirmationDialog<A>(
_ title: Text,
isPresented: Binding<Bool>,
titleVisibility: Visibility = .automatic,
@ContentBuilder actions: () -> A
) -> some View
where A : Viewnonisolated func confirmationDialog<S, A>(
_ title: S,
isPresented: Binding<Bool>,
titleVisibility: Visibility = .automatic,
@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.isPresented*Binding<boolean>A binding to a Boolean value that determines whether to present the dialog. When the user presses or taps the dialog's default action button, the system sets this value to
false, dismissing the dialog.options.titleVisibilitySwiftUI.VisibilityThe visibility of the dialog's title. The default value is
Visibility.automatic.options.actions*ReactNodeA
ContentBuilderreturning the dialog's actions.
Discussion
In the example below, a button conditionally presents a confirmation
dialog depending upon the value of a bound Boolean variable. When the
Boolean value is set to true, the system displays a confirmation
dialog with a cancel action and a destructive action.
struct ConfirmEraseItems: View {
@State private var isShowingDialog = false
var body: some View {
Button("Empty Trash") {
isShowingDialog = true
}
.confirmationDialog(
"Permanently erase the items in the Trash?",
isPresented: $isShowingDialog
) {
Button("Empty Trash", role: .destructive) {
// Handle empty trash action.
}
}
}
}All actions in a confirmation 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 keyboard shortcut.
The system may reorder the buttons based on their role and prominence.
Dialogs include a standard dismiss action by default. If you provide a
button with a role of ButtonRole.cancel, that button takes the place
of the default dismiss action. You don't have to dismiss the
presentation with the cancel button's action.
dialogs as a popover that the user dismisses by tapping anywhere outside the popover, rather than displaying the standard dismiss action.
On iOS, tvOS, and watchOS, confirmation dialogs only support controls
with labels that are Text. Passing any other type of view results in
the content being omitted.
This modifier creates a Text view for the title on your behalf. See
Text for more information about localizing strings.
See also
More in Presentation.
- alertPresents an alert 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.
- dismissalConfirmationDialogPresents a confirmation dialog upon an attempt to dismiss the window for this view.
- 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.