How can I show a toast over a .sheet in SwiftUI

I’m trying to display a toast message over a .sheet in SwiftUI, but no matter what I try, the toast always appears behind the sheet. I’ve tried using ZStack with zIndex, as well as different combinations of view layering, but nothing seems to work.
I even searched and tried solutions suggested by ChatGPT and other forums, but still couldn’t find a working approach. Is there a reliable way to make a toast appear above a .sheet?
If anyone has done this successfully, I’d really appreciate your help or a code example!
Let me know if you’re using any specific toast library like Toast-SwiftUI or a custom implementation — I can tailor the question or solution accordingly
Answer
You can’t display a toast message directly above a .sheet using just SwiftUI.
To achieve this, you need to create a custom UIWindow. This allows you to set its windowLevel high enough to appear above all other views.
approach:
- Create a new UIWindow and set its windowLevel to .alert + 1 to ensure it’s above the main app window.
- Combine SwiftUI and UIKit using UIHostingController. Place your SwiftUI toast view inside that UIWindow.
This way, the toast will appear over everything, including modals and sheets, because it lives in its own window.
P.S. I have a toast library called ToastKit, but at the moment, it does not support UIWindow.
Enjoyed this article?
Check out more content on our blog or follow us on social media.
Browse more articles