Improve orientation and safe area handling

Fix #369
Fix #382
This commit is contained in:
Arkadiusz Fal
2023-05-20 16:04:58 +02:00
parent b53b5eac56
commit f67b1d4feb
14 changed files with 176 additions and 118 deletions

View File

@@ -129,6 +129,7 @@ final class PlayerModel: ObservableObject {
#if os(iOS)
@Published var lockedOrientation: UIInterfaceOrientationMask?
@Default(.rotateToPortraitOnExitFullScreen) private var rotateToPortraitOnExitFullScreen
@Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen
#endif
var accounts: AccountsModel { .shared }
@@ -981,24 +982,21 @@ final class PlayerModel: ObservableObject {
Windows.player.toggleFullScreen()
#endif
playingFullScreen = !isFullScreen
#if os(iOS)
if !playingFullScreen {
playingFullScreen = true
Orientation.lockOrientation(.allButUpsideDown)
if playingFullScreen {
guard rotateToLandscapeOnEnterFullScreen.isRotating else { return }
if currentVideoIsLandscape {
// not sure why but first rotation call is ignore so doing rotate to same orientation first
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: OrientationTracker.shared.currentInterfaceOrientation)
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: rotateToLandscapeOnEnterFullScreen.interaceOrientation)
}
} else {
let rotationOrientation = rotateToPortraitOnExitFullScreen ? UIInterfaceOrientation.portrait : nil
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: rotationOrientation)
// TODO: rework to move view before rotating
if SafeArea.insets.left > 0 {
Delay.by(0.15) {
self.playingFullScreen = false
}
} else {
self.playingFullScreen = false
}
}
#else
playingFullScreen = !isFullScreen
#endif
}
@@ -1036,6 +1034,12 @@ final class PlayerModel: ObservableObject {
#endif
}
var currentVideoIsLandscape: Bool {
guard currentVideo != nil else { return false }
return aspectRatio > 1
}
var formattedSize: String {
guard let videoWidth = backend?.videoWidth, let videoHeight = backend?.videoHeight else { return "unknown" }
return "\(String(format: "%.2f", videoWidth))\u{d7}\(String(format: "%.2f", videoHeight))"