From 1c40065691e32a264da809ce08f8d024703a3b71 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 26 Aug 2022 10:25:07 +0200 Subject: [PATCH] Fix orientation on iOS 16 --- Model/Player/PlayerModel.swift | 4 ++-- Model/Player/PlayerQueue.swift | 2 +- Shared/Player/VideoPlayerView.swift | 8 +++++--- iOS/Orientation.swift | 12 ++++++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 75d24d96..4f3e3912 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -184,7 +184,7 @@ final class PlayerModel: ObservableObject { private var currentArtwork: MPMediaItemArtwork? - var onPresentPlayer: (() -> Void)? + var onPresentPlayer = [() -> Void]() private var remoteCommandCenterConfigured = false init( @@ -373,7 +373,7 @@ final class PlayerModel: ObservableObject { #if os(iOS) if !playingInPictureInPicture, showingPlayer { - onPresentPlayer = { [weak self] in + onPresentPlayer.append { [weak self] in changeBackendHandler?() self?.playNow(video, at: time) } diff --git a/Model/Player/PlayerQueue.swift b/Model/Player/PlayerQueue.swift index 1744dc80..4064e25e 100644 --- a/Model/Player/PlayerQueue.swift +++ b/Model/Player/PlayerQueue.swift @@ -12,7 +12,7 @@ extension PlayerModel { videos.forEach { enqueueVideo($0, loadDetails: false) } #if os(iOS) - onPresentPlayer = { [weak self] in self?.advanceToNextItem() } + onPresentPlayer.append { [weak self] in self?.advanceToNextItem() } #else advanceToNextItem() #endif diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index 92b45335..947253da 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -183,8 +183,8 @@ struct VideoPlayerView: View { .onAnimationCompleted(for: viewDragOffset) { guard !dragGestureState else { return } if viewDragOffset == 0 { - player.onPresentPlayer?() - player.onPresentPlayer = nil + player.onPresentPlayer.forEach { $0() } + player.onPresentPlayer = [] } else if viewDragOffset == Self.hiddenOffset { player.hide(animate: false) } @@ -506,7 +506,9 @@ struct VideoPlayerView: View { player.enterFullScreen(showControls: false) } - Orientation.lockOrientation(.allButUpsideDown, andRotateTo: currentOrientation) + player.onPresentPlayer.append { + Orientation.lockOrientation(.allButUpsideDown, andRotateTo: currentOrientation) + } } orientationObserver = NotificationCenter.default.addObserver( diff --git a/iOS/Orientation.swift b/iOS/Orientation.swift index 68d605d7..466672bd 100644 --- a/iOS/Orientation.swift +++ b/iOS/Orientation.swift @@ -32,5 +32,17 @@ struct Orientation { UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation") UINavigationController.attemptRotationToDeviceOrientation() + + if #available(iOS 16, *) { + guard let windowScene = SafeArea.scene else { return } + let rotateOrientationMask = rotateOrientation == .portrait ? UIInterfaceOrientationMask.portrait : + rotateOrientation == .landscapeLeft ? .landscapeLeft : + rotateOrientation == .landscapeRight ? .landscapeRight : + .allButUpsideDown + + windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: rotateOrientationMask)) { error in + print("denied rotation \(error)") + } + } } }