Look up the foreground scene instead of the first connected one

The swipe-action share sheet, the expanded player's safe area and the
Dynamic Island side check took connectedScenes.first, which ignores
which scene is active (on the iPhone Duo it can be the other panel's)
and presented the share sheet from the main window, behind an expanded
player.

UIApplication.foregroundWindowScene/foregroundWindow resolve the
foreground-active scene (else foreground-inactive, else any) and its
key window, the order the widescreen layout already used. The share
sheet now presents from the key window, which is the player's while it
is up. The tvOS display mode manager uses the same lookup.
This commit is contained in:
Arkadiusz Fal
2026-10-04 23:27:18 +02:00
parent 1c7314f74a
commit 5f31610489
6 changed files with 38 additions and 26 deletions

View File

@@ -146,12 +146,7 @@ final class TVDisplayModeManager {
}
private func activeDisplayManager() -> AVDisplayManager? {
let scenes = UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
let scene = scenes.first { $0.activationState == .foregroundActive }
?? scenes.first
let window = scene?.windows.first { $0.isKeyWindow } ?? scene?.windows.first
return window?.avDisplayManager
UIApplication.shared.foregroundWindow?.avDisplayManager
}
private func makeFormatDescription(for dynamicRange: TVDisplayDynamicRange) -> CMVideoFormatDescription {