From c33d66ca1fd3942742f301915608f5c2ad6aea86 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 26 Sep 2026 21:00:18 +0200 Subject: [PATCH] Keep the landscape panel in place while Notification Center is open WideScreenPlayerLayout looked up safe area insets and window bounds only from a foregroundActive scene. Notification Center and Control Center move the scene to foregroundInactive, so the lookup failed, insets dropped to zero and the panel and video jumped to the screen edge. Fall back to an inactive foreground scene (and then any scene) before giving up. --- .../Views/Player/WideScreenPlayerLayout.swift | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Yattee/Views/Player/WideScreenPlayerLayout.swift b/Yattee/Views/Player/WideScreenPlayerLayout.swift index d46596c8..8c699389 100644 --- a/Yattee/Views/Player/WideScreenPlayerLayout.swift +++ b/Yattee/Views/Player/WideScreenPlayerLayout.swift @@ -106,14 +106,24 @@ struct WideScreenPlayerLayout: View { settingsManager?.detailsPanelLastVisible = false } + #if os(iOS) + /// The app's window, looked up from any foreground scene. Notification + /// Center and Control Center move the scene to `.foregroundInactive`, so + /// requiring `.foregroundActive` would drop the safe area to zero while + /// they are open and make the panel jump to the screen edge. + private var foregroundWindow: UIWindow? { + let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene } + let scene = scenes.first { $0.activationState == .foregroundActive } + ?? scenes.first { $0.activationState == .foregroundInactive } + ?? scenes.first + return scene?.windows.first { $0.isKeyWindow } ?? scene?.windows.first + } + #endif + /// Get safe area insets from window scene (geometry reader insets are 0 when .ignoresSafeArea is used) private var windowSafeAreaInsets: EdgeInsets { #if os(iOS) - guard let windowScene = UIApplication.shared.connectedScenes - .compactMap({ $0 as? UIWindowScene }) - .first(where: { $0.activationState == .foregroundActive }), - let window = windowScene.windows.first - else { return EdgeInsets() } + guard let window = foregroundWindow else { return EdgeInsets() } let insets = window.safeAreaInsets return EdgeInsets(top: insets.top, leading: insets.left, bottom: insets.bottom, trailing: insets.right) #else @@ -125,11 +135,7 @@ struct WideScreenPlayerLayout: View { /// On macOS, this is not used - geometry reader size is used directly private var windowSceneBounds: CGSize { #if os(iOS) - guard let windowScene = UIApplication.shared.connectedScenes - .compactMap({ $0 as? UIWindowScene }) - .first(where: { $0.activationState == .foregroundActive }), - let window = windowScene.windows.first - else { + guard let window = foregroundWindow else { // Fallback to screen bounds let screen = UIScreen.main.bounds return CGSize(width: max(screen.width, screen.height), height: min(screen.width, screen.height))