I am adding an overlay[alert] to very first parent View of the application. I need to show this overlay from a sheet, but this overlay got covered by the sheet.
@main
struct ToastApp: App {
@State var showAlert: Bool = false
var body: some Scene {
WindowGroup {
ContentView(showAlert: $showAlert)
.overlay(alignment: .center, content: {
if showAlert {
VStack {
Text("I am alert")
Text("I am alert Description")
}
.frame(width: 270)
.background(Color.gray)
}
})
}
}
}
struct ContentView: View {
@State var showSheet: Bool = false
@Binding var showAlert: Bool
var body: some View {
VStack {
Text("Application Most Parent")
Button("Show Sheet") {
showSheet = true
}
}
.sheet(isPresented: $showSheet) {
Button("Show Toast") {
showAlert = true
}
.presentationDetents([.fraction(0.5)])
}
}
}
Requirements: I want to keep the custom alert in middle of screen.
Please help.