1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30

Fix orientation (#121)

This commit is contained in:
Arkadiusz Fal 2022-05-29 15:34:40 +02:00
parent c48d478f64
commit 71de78113d
5 changed files with 14 additions and 25 deletions

View File

@ -252,9 +252,9 @@ final class MPVBackend: PlayerBackend {
model.toggleFullscreen(controls?.playingFullscreen ?? false) model.toggleFullscreen(controls?.playingFullscreen ?? false)
#if os(iOS) #if os(iOS)
if Defaults[.lockLandscapeWhenEnteringFullscreen] { if Defaults[.lockOrientationInFullScreen] {
Orientation.lockOrientation(.landscape, andRotateTo: UIDevice.current.orientation.isLandscape ? nil : .landscapeRight) Orientation.lockOrientation(.landscape, andRotateTo: UIDevice.current.orientation.isLandscape ? nil : .landscapeRight)
} }
#endif #endif
} }

View File

@ -83,8 +83,7 @@ extension Defaults.Keys {
#if os(iOS) #if os(iOS)
static let honorSystemOrientationLock = Key<Bool>("honorSystemOrientationLock", default: true) static let honorSystemOrientationLock = Key<Bool>("honorSystemOrientationLock", default: true)
static let enterFullscreenInLandscape = Key<Bool>("enterFullscreenInLandscape", default: UIDevice.current.userInterfaceIdiom == .phone) static let enterFullscreenInLandscape = Key<Bool>("enterFullscreenInLandscape", default: UIDevice.current.userInterfaceIdiom == .phone)
static let lockLandscapeOnRotation = Key<Bool>("lockLandscapeOnRotation", default: false) static let lockOrientationInFullScreen = Key<Bool>("lockOrientationInFullScreen", default: false)
static let lockLandscapeWhenEnteringFullscreen = Key<Bool>("lockLandscapeWhenEnteringFullscreen", default: false)
#endif #endif
} }

View File

@ -141,7 +141,7 @@ extension AppleAVPlayerViewController: AVPlayerViewControllerDelegate {
willBeginFullScreenPresentationWithAnimationCoordinator context: UIViewControllerTransitionCoordinator willBeginFullScreenPresentationWithAnimationCoordinator context: UIViewControllerTransitionCoordinator
) { ) {
#if os(iOS) #if os(iOS)
if !context.isCancelled, Defaults[.lockLandscapeWhenEnteringFullscreen] { if !context.isCancelled, Defaults[.lockOrientationInFullScreen] {
Orientation.lockOrientation(.landscape, andRotateTo: UIDevice.current.orientation.isLandscape ? nil : .landscapeRight) Orientation.lockOrientation(.landscape, andRotateTo: UIDevice.current.orientation.isLandscape ? nil : .landscapeRight)
} }
#endif #endif

View File

@ -34,7 +34,7 @@ struct VideoPlayerView: View {
@Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape @Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape
@Default(.honorSystemOrientationLock) private var honorSystemOrientationLock @Default(.honorSystemOrientationLock) private var honorSystemOrientationLock
@Default(.lockLandscapeOnRotation) private var lockLandscapeOnRotation @Default(.lockOrientationInFullScreen) private var lockOrientationInFullScreen
@State private var motionManager: CMMotionManager! @State private var motionManager: CMMotionManager!
@State private var orientation = UIInterfaceOrientation.portrait @State private var orientation = UIInterfaceOrientation.portrait
@ -441,7 +441,7 @@ struct VideoPlayerView: View {
Orientation.lockOrientation(orientationLockMask, andRotateTo: orientation) Orientation.lockOrientation(orientationLockMask, andRotateTo: orientation)
guard lockLandscapeOnRotation else { guard lockOrientationInFullScreen else {
return return
} }
@ -451,7 +451,7 @@ struct VideoPlayerView: View {
guard abs(acceleration.z) <= 0.74, guard abs(acceleration.z) <= 0.74,
player.lockedOrientation.isNil, player.lockedOrientation.isNil,
enterFullscreenInLandscape, enterFullscreenInLandscape,
!lockLandscapeOnRotation !lockOrientationInFullScreen
else { else {
return return
} }
@ -470,7 +470,7 @@ struct VideoPlayerView: View {
let newOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation let newOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
if newOrientation?.isLandscape ?? false, if newOrientation?.isLandscape ?? false,
player.presentingPlayer, player.presentingPlayer,
lockLandscapeOnRotation, lockOrientationInFullScreen,
!player.lockedOrientation.isNil !player.lockedOrientation.isNil
{ {
Orientation.lockOrientation(.landscape, andRotateTo: newOrientation) Orientation.lockOrientation(.landscape, andRotateTo: newOrientation)

View File

@ -17,9 +17,8 @@ struct PlayerSettings: View {
@Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer @Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer
#if os(iOS) #if os(iOS)
@Default(.honorSystemOrientationLock) private var honorSystemOrientationLock @Default(.honorSystemOrientationLock) private var honorSystemOrientationLock
@Default(.lockLandscapeOnRotation) private var lockLandscapeOnRotation @Default(.lockOrientationInFullScreen) private var lockOrientationInFullScreen
@Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape @Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape
@Default(.lockLandscapeWhenEnteringFullscreen) private var lockLandscapeWhenEnteringFullscreen
#endif #endif
@Default(.closePiPOnNavigation) private var closePiPOnNavigation @Default(.closePiPOnNavigation) private var closePiPOnNavigation
@Default(.closePiPOnOpeningPlayer) private var closePiPOnOpeningPlayer @Default(.closePiPOnOpeningPlayer) private var closePiPOnOpeningPlayer
@ -96,13 +95,12 @@ struct PlayerSettings: View {
} }
#if os(iOS) #if os(iOS)
Section(header: SettingsHeader(text: "Orientation"), footer: orientationFooter) { Section(header: SettingsHeader(text: "Orientation")) {
if idiom == .pad { if idiom == .pad {
enterFullscreenInLandscapeToggle enterFullscreenInLandscapeToggle
} }
honorSystemOrientationLockToggle honorSystemOrientationLockToggle
lockLandscapeOnRotationToggle lockOrientationInFullScreenToggle
lockLandscapeWhenEnteringFullscreenToggle
} }
#endif #endif
} }
@ -215,18 +213,10 @@ struct PlayerSettings: View {
Toggle("Enter fullscreen in landscape", isOn: $enterFullscreenInLandscape) Toggle("Enter fullscreen in landscape", isOn: $enterFullscreenInLandscape)
} }
private var lockLandscapeOnRotationToggle: some View { private var lockOrientationInFullScreenToggle: some View {
Toggle("Lock landscape on rotation", isOn: $lockLandscapeOnRotation) Toggle("Lock orientation in fullscreen", isOn: $lockOrientationInFullScreen)
.disabled(!enterFullscreenInLandscape) .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 #endif
private var closePiPOnNavigationToggle: some View { private var closePiPOnNavigationToggle: some View {