AlertScene
A scene that renders itself as a standalone alert dialog.
Declaration
struct AlertScene<Actions, Message> where Actions : View, Message : ViewOverview
Alert scenes are not attached to any particular window, and present themselves in the center of the current display. The dialog must be dismissed before any further interaction with the app is permitted.
@main
struct MyApp: App {
@State var showLoginAlert = true
@State var loggedIn = false
var body: some Scene {
Window("Welcome User Window", id:"WelcomeWindow") {
...
}
.defaultLaunchBehavior(loggedIn ? .presented : .suppressed)
AlertScene("Login Required", isPresented: $showLoginAlert) {
Button("OK") {
...
}
}
}
}All actions present in the ViewBuilder will dismiss the alert. Like the alert modifier, you can determine the role of the buttons with .cancel or .destructive. If no actions are present, we will automatically include an OK button for dismissal.