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
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:
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.