How to display a toast view above both main content and FullScreenCover in SwiftUI?

I'm using a ZStack with viewA() and a toast viewB(). I present a FullScreenView() using .fullScreenCover(isPresented:).

ZStack {
  viewA()
  viewB() // toast view
}
.fullScreenCover(isPresented: $isPresented) {
  FullScreenView()
}

I want viewB (the toast) to appear above both viewA and the FullScreenView. I only found this approach works but it has duplicate code.

ZStack {
  viewA()
  viewB() // toast view
}
.fullScreenCover(isPresented: $isPresented) {
  ZStack {
    FullScreenModalView()
    viewB() // toast view
  }
}

What are all possible approaches to achieve this in SwiftUI? Any advice or code samples would be appreciated!

Answered by DTS Engineer in 863554022

Have you considered using a system component like an action sheet or an Alert instead of a custom component?

Have you considered using a system component like an action sheet or an Alert instead of a custom component?

How to display a toast view above both main content and FullScreenCover in SwiftUI?
 
 
Q