79582764

Date: 2025-04-19 19:30:50
Score: 1
Natty:
Report link

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:

  1. Create a new UIWindow and set its windowLevel to .alert + 1 to ensure it’s above the main app window.
  2. 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.

https://github.com/Desp0o/ToastKit

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Tornike Despotashvili