Fix orientation on iOS 16

This commit is contained in:
Arkadiusz Fal 2022-08-26 10:25:07 +02:00
parent 653cca07fe
commit fc7052a7fa
4 changed files with 20 additions and 6 deletions

View File

@ -184,7 +184,7 @@ final class PlayerModel: ObservableObject {
private var currentArtwork: MPMediaItemArtwork?
var onPresentPlayer: (() -> Void)?
var onPresentPlayer = [() -> Void]()
private var remoteCommandCenterConfigured = false
init(
@ -373,7 +373,7 @@ final class PlayerModel: ObservableObject {
#if os(iOS)
if !playingInPictureInPicture, showingPlayer {
onPresentPlayer = { [weak self] in
onPresentPlayer.append { [weak self] in
changeBackendHandler?()
self?.playNow(video, at: time)
}

View File

@ -12,7 +12,7 @@ extension PlayerModel {
videos.forEach { enqueueVideo($0, loadDetails: false) }
#if os(iOS)
onPresentPlayer = { [weak self] in self?.advanceToNextItem() }
onPresentPlayer.append { [weak self] in self?.advanceToNextItem() }
#else
advanceToNextItem()
#endif

View File

@ -183,8 +183,8 @@ struct VideoPlayerView: View {
.onAnimationCompleted(for: viewDragOffset) {
guard !dragGestureState else { return }
if viewDragOffset == 0 {
player.onPresentPlayer?()
player.onPresentPlayer = nil
player.onPresentPlayer.forEach { $0() }
player.onPresentPlayer = []
} else if viewDragOffset == Self.hiddenOffset {
player.hide(animate: false)
}
@ -506,7 +506,9 @@ struct VideoPlayerView: View {
player.enterFullScreen(showControls: false)
}
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: currentOrientation)
player.onPresentPlayer.append {
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: currentOrientation)
}
}
orientationObserver = NotificationCenter.default.addObserver(

View File

@ -32,5 +32,17 @@ struct Orientation {
UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
UINavigationController.attemptRotationToDeviceOrientation()
if #available(iOS 16, *) {
guard let windowScene = SafeArea.scene else { return }
let rotateOrientationMask = rotateOrientation == .portrait ? UIInterfaceOrientationMask.portrait :
rotateOrientation == .landscapeLeft ? .landscapeLeft :
rotateOrientation == .landscapeRight ? .landscapeRight :
.allButUpsideDown
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: rotateOrientationMask)) { error in
print("denied rotation \(error)")
}
}
}
}