DismissWindowAction
An action that dismisses a window associated to a particular scene.
Declaration
type DismissWindowAction = { (): Promise<void>; (options: { id: string; }): Promise<void>; (options: { id: string; value: unknown; }): Promise<void>; (options: { value: unknown; }): Promise<void>; };@MainActor @preconcurrency struct DismissWindowActionOverview
Use the EnvironmentValues.dismissWindow environment value to get the
instance of this structure for a given Environment. Then call the
instance to dismiss a window. You call the instance directly because it
defines a DismissWindowAction.callAsFunction(id:) method that Swift
calls when you call the instance.
For example, you can define a button that closes an auxiliary window:
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
#if os(macOS)
Window("Auxiliary", id: "auxiliary") {
AuxiliaryContentView()
}
#endif
}
}
struct DismissWindowButton: View {
@Environment(\.dismissWindow) private var dismissWindow
var body: some View {
Button("Close Auxiliary Window") {
dismissWindow(id: "auxiliary")
}
}
}If the window was opened with EnvironmentValues.pushWindow, the original
presenting will reappear when this action is performed.
From Apple’s SwiftUI documentation. Code samples there are Swift.
See also
More in Presentation.
- AutomaticPresentationSizingThe default presentation sizing, appropriate for the platform.
- DismissActionAn action that dismisses a presentation.
- DismissBehaviorProgrammatic window dismissal behaviors.
- FileDialogBrowserOptionsThe way that file dialogs present the file system.
- FittedPresentationSizingThe size of the presentation is dictated by the ideal size of the content.
- FormPresentationSizingThe size is appropriate for forms and slightly less wide than.page
- MenuActionDismissBehaviorThe set of menu dismissal behavior options.
- MenuOrderThe order in which a menu presents its content.
- PagePresentationSizingThe size is roughly the size of a page of paper, appropriate for informational or compositional content.
- PopoverAttachmentAnchorAn attachment anchor for a popover.
- PresentationAdaptationStrategies for adapting a presentation to a different size class.
- PresentationBackgroundInteractionThe kinds of interaction available to views behind a presentation.