presentationBackgroundInteraction
Controls whether people can interact with the view behind a presentation.
View ModifieriOS 16.4+macOS 13.3+tvOS 16.4+watchOS 9.4+presentationBackgroundInteraction(_:) in SwiftUI
Declaration
compose().presentationBackgroundInteraction(
interaction: SwiftUI.PresentationBackgroundInteraction
)nonisolated func presentationBackgroundInteraction(
_ interaction: PresentationBackgroundInteraction
) -> some ViewParameters
interaction*SwiftUI.PresentationBackgroundInteractionA specification of how people can interact with the view behind a presentation.
Discussion
On many platforms, SwiftUI automatically disables the view behind a sheet that you present, so that people can't interact with the backing view until they dismiss the sheet. Use this modifier if you want to enable interaction.
The following example enables people to interact with the view behind the sheet when the sheet is at the smallest detent, but not at the other detents:
struct ContentView: View {
@State private var showSettings = false
var body: some View {
Button("View Settings") {
showSettings = true
}
.sheet(isPresented: $showSettings) {
SettingsView()
.presentationDetents(
[.height(120), .medium, .large])
.presentationBackgroundInteraction(
.enabled(upThrough: .height(120)))
}
}
}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.
- 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.