TL;DR My: my app has some global alerts and modals (e.g. hints about trial limits, the in-app purchase screentscreens, etc.) which should be availabelavailable through out the app. In UIKitUIKit I could always present alerts or modals on the topmost view controller, no matter what was currently presented. In SwiftUISwiftUI, .alert and .sheet are tied to the local view hierarchy, so triggering an alert from inside a sheet dismisses the sheet first.
Is there a SwiftUISwiftUI-native pattern for presenting global alerts/sheets/modals on top of everything—without UIKitUIKit bridging and without rebuilding custom alert UIs?
Question
I’m looking for a way in SwiftUISwiftUI to show app-wide alerts or sheets, regardless of where the user currently is in the view hierarchy.
In UIKitUIKit this was simple: I just walked up the presentedViewController chain and called present(...) on the topmost view controller.
In SwiftUISwiftUI, this approach doesn’t translate because .alert and .sheet, etc. belong to the currently visible view hierarchy.
The issue: If the alert is triggered inside the presented sheet (SubViewA), SwiftUISwiftUI first dismisses the .sheet and only then shows the alert. So I cannot display a “global” alert on top of an existing .sheet. Showing another .sheet (or .fullscreenCover) over the existing sheet also fails.
What I’m looking for
A pure SwiftUI I’m looking for a pure SwiftUI solution that:
- no has no fallback to
UIKitUIKit - allows global alert/sheet presentation
- shows them above currently presented sheets
- does not rely on UIKit (UIViewController, present(...))
- does not require fully custom alert implementations
In other words:
Is there a recommended, SwiftUI-nativeSwiftUI-native pattern for global, hierarchy-independent modal presentation? Or is this simply not possible with SwiftUI’s current presentation system?