From dd003db26154811845503bae85352e001fc3f705 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 29 May 2022 15:34:40 +0200 Subject: [PATCH] Fix orientation (#121) --- Model/Player/Backends/MPVBackend.swift | 6 +++--- Shared/Defaults.swift | 3 +-- .../Player/AppleAVPlayerViewController.swift | 2 +- Shared/Player/VideoPlayerView.swift | 8 ++++---- Shared/Settings/PlayerSettings.swift | 20 +++++-------------- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index 1dca3342..630ec1cf 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -252,9 +252,9 @@ final class MPVBackend: PlayerBackend { model.toggleFullscreen(controls?.playingFullscreen ?? false) #if os(iOS) - if Defaults[.lockLandscapeWhenEnteringFullscreen] { - Orientation.lockOrientation(.landscape, andRotateTo: UIDevice.current.orientation.isLandscape ? nil : .landscapeRight) - } + if Defaults[.lockOrientationInFullScreen] { + Orientation.lockOrientation(.landscape, andRotateTo: UIDevice.current.orientation.isLandscape ? nil : .landscapeRight) + } #endif } diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 924c2154..0a7a3d95 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -83,8 +83,7 @@ extension Defaults.Keys { #if os(iOS) static let honorSystemOrientationLock = Key("honorSystemOrientationLock", default: true) static let enterFullscreenInLandscape = Key("enterFullscreenInLandscape", default: UIDevice.current.userInterfaceIdiom == .phone) - static let lockLandscapeOnRotation = Key("lockLandscapeOnRotation", default: false) - static let lockLandscapeWhenEnteringFullscreen = Key("lockLandscapeWhenEnteringFullscreen", default: false) + static let lockOrientationInFullScreen = Key("lockOrientationInFullScreen", default: false) #endif } diff --git a/Shared/Player/AppleAVPlayerViewController.swift b/Shared/Player/AppleAVPlayerViewController.swift index d341c696..890fa388 100644 --- a/Shared/Player/AppleAVPlayerViewController.swift +++ b/Shared/Player/AppleAVPlayerViewController.swift @@ -141,7 +141,7 @@ extension AppleAVPlayerViewController: AVPlayerViewControllerDelegate { willBeginFullScreenPresentationWithAnimationCoordinator context: UIViewControllerTransitionCoordinator ) { #if os(iOS) - if !context.isCancelled, Defaults[.lockLandscapeWhenEnteringFullscreen] { + if !context.isCancelled, Defaults[.lockOrientationInFullScreen] { Orientation.lockOrientation(.landscape, andRotateTo: UIDevice.current.orientation.isLandscape ? nil : .landscapeRight) } #endif diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index fe331b31..897bc097 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -34,7 +34,7 @@ struct VideoPlayerView: View { @Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape @Default(.honorSystemOrientationLock) private var honorSystemOrientationLock - @Default(.lockLandscapeOnRotation) private var lockLandscapeOnRotation + @Default(.lockOrientationInFullScreen) private var lockOrientationInFullScreen @State private var motionManager: CMMotionManager! @State private var orientation = UIInterfaceOrientation.portrait @@ -441,7 +441,7 @@ struct VideoPlayerView: View { Orientation.lockOrientation(orientationLockMask, andRotateTo: orientation) - guard lockLandscapeOnRotation else { + guard lockOrientationInFullScreen else { return } @@ -451,7 +451,7 @@ struct VideoPlayerView: View { guard abs(acceleration.z) <= 0.74, player.lockedOrientation.isNil, enterFullscreenInLandscape, - !lockLandscapeOnRotation + !lockOrientationInFullScreen else { return } @@ -470,7 +470,7 @@ struct VideoPlayerView: View { let newOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation if newOrientation?.isLandscape ?? false, player.presentingPlayer, - lockLandscapeOnRotation, + lockOrientationInFullScreen, !player.lockedOrientation.isNil { Orientation.lockOrientation(.landscape, andRotateTo: newOrientation) diff --git a/Shared/Settings/PlayerSettings.swift b/Shared/Settings/PlayerSettings.swift index 89cf5f19..19857c0b 100644 --- a/Shared/Settings/PlayerSettings.swift +++ b/Shared/Settings/PlayerSettings.swift @@ -17,9 +17,8 @@ struct PlayerSettings: View { @Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer #if os(iOS) @Default(.honorSystemOrientationLock) private var honorSystemOrientationLock - @Default(.lockLandscapeOnRotation) private var lockLandscapeOnRotation + @Default(.lockOrientationInFullScreen) private var lockOrientationInFullScreen @Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape - @Default(.lockLandscapeWhenEnteringFullscreen) private var lockLandscapeWhenEnteringFullscreen #endif @Default(.closePiPOnNavigation) private var closePiPOnNavigation @Default(.closePiPOnOpeningPlayer) private var closePiPOnOpeningPlayer @@ -96,13 +95,12 @@ struct PlayerSettings: View { } #if os(iOS) - Section(header: SettingsHeader(text: "Orientation"), footer: orientationFooter) { + Section(header: SettingsHeader(text: "Orientation")) { if idiom == .pad { enterFullscreenInLandscapeToggle } honorSystemOrientationLockToggle - lockLandscapeOnRotationToggle - lockLandscapeWhenEnteringFullscreenToggle + lockOrientationInFullScreenToggle } #endif } @@ -215,18 +213,10 @@ struct PlayerSettings: View { Toggle("Enter fullscreen in landscape", isOn: $enterFullscreenInLandscape) } - private var lockLandscapeOnRotationToggle: some View { - Toggle("Lock landscape on rotation", isOn: $lockLandscapeOnRotation) + private var lockOrientationInFullScreenToggle: some View { + Toggle("Lock orientation in fullscreen", isOn: $lockOrientationInFullScreen) .disabled(!enterFullscreenInLandscape) } - - private var lockLandscapeWhenEnteringFullscreenToggle: some View { - Toggle("Rotate and lock landscape on entering fullscreen", isOn: $lockLandscapeWhenEnteringFullscreen) - } - - private var orientationFooter: some View { - Text("Orientation settings are experimental and do not yet work properly with all devices and iOS versions") - } #endif private var closePiPOnNavigationToggle: some View {