Toast Alert SwiftUI display problems

Viewed 483

I'm currently trying to use the AlertToast in my SwiftUI project, the alert seems to be working but it looks like it is being displayed in the button that it is called from.

Attaching an example:

Toast Alerts SwiftUI

My Code:

struct ButtonsGroup: View {
@State private var showingAlert = false
@State private var showingSheet = false
@State private var showingActionSheet = false
@State private var showButtonSheet = false
@State private var showToast = false

var body: some View {
    
    VStack{

                Button("Show Toast"){
                     showToast.toggle()
                }
            }
            .toast(isPresenting: $showToast){

                // `.alert` is the default displayMode
                AlertToast(displayMode: .banner(.slide), type: .regular, title: "Message Sent!")
                
                //Choose .hud to toast alert from the top of the screen
                //AlertToast(displayMode: .hud, type: .regular, title: "Message Sent!")
                
                //Choose .banner to slide/pop alert from the bottom of the screen
                //AlertToast(displayMode: .banner(.slide), type: .regular, title: "Message Sent!")
            }
}
}

I've looked up the documentation and copy the code, but it seems that the problem persists.

My Goal is to show the alert either at the top of the screen, or the middle. Thanks in advance!

0 Answers
Related