From fe9b7c03ca65ed4a31996da156ab488679512f47 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 13 Nov 2022 13:15:44 +0100 Subject: [PATCH] Fix orientation issues --- Shared/Player/PlayerOrientation.swift | 8 +++++--- Shared/Player/VideoPlayerView.swift | 10 +++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Shared/Player/PlayerOrientation.swift b/Shared/Player/PlayerOrientation.swift index ed3b6826..37fce9b1 100644 --- a/Shared/Player/PlayerOrientation.swift +++ b/Shared/Player/PlayerOrientation.swift @@ -7,11 +7,13 @@ extension VideoPlayerView { let currentOrientation = OrientationTracker.shared.currentInterfaceOrientation if currentOrientation.isLandscape, Defaults[.enterFullscreenInLandscape], + !Defaults[.honorSystemOrientationLock], !player.playingFullScreen, - !player.playingInPictureInPicture + !player.currentItem.isNil, + player.lockedOrientation.isNil || player.lockedOrientation!.contains(.landscape), + !player.playingInPictureInPicture, + player.presentingPlayer { - guard player.presentingPlayer else { return } - DispatchQueue.main.async { player.controls.presentingControls = false player.enterFullScreen(showControls: false) diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index d6338c42..86fc951d 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -55,6 +55,7 @@ struct VideoPlayerView: View { @State internal var isVerticalDrag = false @State internal var viewDragOffset = Self.hiddenOffset @State internal var orientationObserver: Any? + @State internal var orientationNotification: Any? #endif @EnvironmentObject internal var player @@ -144,6 +145,8 @@ struct VideoPlayerView: View { orientationMask, andRotateTo: orientationMask == .landscapeLeft ? .landscapeLeft : orientationMask == .landscapeRight ? .landscapeRight : .portrait ) + } else { + Orientation.lockOrientation(.allButUpsideDown) } } } @@ -155,8 +158,13 @@ struct VideoPlayerView: View { } stopOrientationUpdates() player.controls.hideOverlays() + } + .onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in + guard player.lockedOrientation.isNil else { + return + } - player.lockedOrientation = nil + Orientation.lockOrientation(.allButUpsideDown, andRotateTo: OrientationTracker.shared.currentInterfaceOrientation) } .onAnimationCompleted(for: viewDragOffset) { guard !dragGestureState else { return }