dialogSuppressionToggle
Enables user suppression of dialogs and alerts presented within self, with a custom suppression message on macOS. Unused on other platforms.
Overloads
2 ways to call compose().dialogSuppressionToggle(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().dialogSuppressionToggle(
titleResource: string,
options: {
isSuppressed: Binding<boolean>;
}
)@export(implementation) nonisolated func dialogSuppressionToggle(
_ titleResource: LocalizedStringResource,
isSuppressed: Binding<Bool>
) -> some View3 more Swift overloads share this form
nonisolated func dialogSuppressionToggle(
_ titleKey: LocalizedStringKey,
isSuppressed: Binding<Bool>
) -> some Viewnonisolated func dialogSuppressionToggle(
_ label: Text,
isSuppressed: Binding<Bool>
) -> some Viewnonisolated func dialogSuppressionToggle<S>(
_ title: S,
isSuppressed: Binding<Bool>
) -> some View
where S : StringProtocolParameters
titleResource*stringThe title of the suppression toggle in the dialog. This parameter can be elided to use the default suppression title.
options.isSuppressed*Binding<boolean>Whether the suppression toggle is on or off in the dialog.
Discussion
Applying dialog suppression adds a toggle to dialogs on macOS,
which allows the user to request the alert not be displayed again.
Typically whether a dialog is suppressed is stored in AppStorage
and used to decide whether to present the dialog in the future.
The following example configures a confirmationDialog with a
suppression toggle. The toggle's state is stored in AppStorage and
used to determine whether or not to show the dialog when the
"Delete Items" button is pressed.
struct ConfirmEraseItems: View {
@State private var isShowingDialog = false
@AppStorage("suppressEraseItemAlert")
private var suppressAlert = false
var body: some View {
Button("Delete Items") {
if !suppressAlert {
isShowingDialog = true
} else {
// Handle item deletion.
}
}
.confirmationDialog(
"Are you sure you want to erase these items?",
isPresented: $isShowingDialog
) {
Button("Erase", role: .destructive) {
// Handle item deletion.
}
Button("Cancel", role: .cancel) {
isShowingDialog = false
}
}
.dialogSuppressionToggle(
"Do not ask about erasing items again",
isSuppressed: $suppressAlert)
}
}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.
- 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.