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)
#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
}

View File

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

View File

@ -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

View File

@ -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)

View File

@ -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 {