-
-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Labels
Description
When using Mijick/Popups in a SwiftUI app, the popup background (dim layer) appears, but the popup content view is not rendered.
the issue occurs only when @Environment(.scenePhase) is declared in the App struct.
@main
struct MyApp: App {
@Environment(\.scenePhase) private var scenePhase // <- causes the issue
var body: some Scene {
WindowGroup {
RootView().registerPopups()
}
}
}
struct RootView: View {
var body: some View {
Text("Hello")
.onAppear {
ToastView.show("Hello")
}
}
}
Declaring @Environment(.scenePhase) in the App struct causes SwiftUI to rebuild the Scene / Window hierarchy during lifecycle changes.
Mijick/Popups attaches its popup host to the current window overlay.
When the Scene is rebuilt:
• the background layer may be recreated
• but the popup content’s hosting container is lost
This results in only the background being shown.
This is not obvious and very easy to trigger unintentionally.
Alternative: Use UIKit lifecycle notifications in App
@main
struct MyApp: App {
init() {
NotificationCenter.default.addObserver(
forName: UIApplication.didEnterBackgroundNotification,
object: nil,
queue: .main
) { _ in
print("Entered background")
}
}
var body: some Scene {
WindowGroup {
RootView().registerPopups()
}
}
}
Reactions are currently unavailable