Minor UI fixes, force orientation (#857)

This commit is contained in:
Tony 2023-09-25 14:47:50 -07:00 committed by GitHub
parent 10a1418d04
commit a2f9da506c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 20 deletions

View File

@ -41,9 +41,9 @@ final class VideoPlayerCoordinator: NavigationCoordinatable {
}
.ignoresSafeArea()
.hideSystemOverlays()
// .onAppear {
// AppDelegate.changeOrientation(.landscape)
// }
.onAppear {
AppDelegate.enterPlaybackOrientation()
}
#else

View File

@ -38,17 +38,37 @@ class AppDelegate: NSObject, UIApplicationDelegate {
AppDelegate.orientationLock
}
static func changeOrientation(_ orientation: UIInterfaceOrientationMask) {
static func enterPlaybackOrientation() {
AppDelegate.changeOrientation(.landscape)
}
// guard UIDevice.isPhone else { return }
//
// Self.orientationLock = orientation
//
// if #available(iOS 16, *) {
// let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
// windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientation))
// } else {
// UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
// }
static func leavePlaybackOrientation() {
if UIDevice.isIPad {
AppDelegate.changeOrientation(.allButUpsideDown)
} else {
// On iPhone, users likely want to return to portrait mode after leaving playback.
// However, we don't want to lock them into portrait mode, so switch back after a delay.
AppDelegate.changeOrientation(.portrait)
// 0.25 seconds is about the time to switch from landscape to portrait.
// Changing orientation again too early will cause the top time/battery bar to remain
// at the side instead of moving up top, like it should.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
AppDelegate.changeOrientation(.allButUpsideDown)
}
}
}
private static func changeOrientation(_ orientation: UIInterfaceOrientationMask) {
guard UIDevice.isPhone || UIDevice.isIPad else { return }
orientationLock = orientation
if #available(iOS 16, *) {
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientation))
} else {
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
}
}
}

View File

@ -67,6 +67,9 @@ extension VideoPlayer.Overlay {
}
.padding(.leading, safeAreaInsets.leading)
.padding(.trailing, safeAreaInsets.trailing)
.if(UIDevice.isIPad) { view in
view.padding(.horizontal)
}
ScrollViewReader { proxy in
ScrollView(.horizontal, showsIndicators: false) {
@ -118,6 +121,9 @@ extension VideoPlayer.Overlay {
.padding(.leading, safeAreaInsets.leading)
.padding(.trailing, safeAreaInsets.trailing)
.padding(.bottom)
.if(UIDevice.isIPad) { view in
view.padding(.horizontal)
}
}
.onChange(of: currentOverlayType) { newValue in
guard newValue == .chapters else { return }

View File

@ -29,13 +29,13 @@ extension VideoPlayer.Overlay {
HStack(alignment: .center) {
Button {
videoPlayerProxy.stop()
router.dismissCoordinator {
AppDelegate.changeOrientation(.portrait)
}
AppDelegate.leavePlaybackOrientation()
router.dismissCoordinator()
} label: {
Image(systemName: "xmark")
.padding()
}
.contentShape(Rectangle())
.buttonStyle(ScalingButtonStyle(scale: 0.8))
Text(viewModel.item.displayTitle)

View File

@ -130,9 +130,8 @@ struct VideoPlayer: View {
{
videoPlayerManager.selectNextViewModel()
} else {
router.dismissCoordinator {
AppDelegate.changeOrientation(.portrait)
}
AppDelegate.leavePlaybackOrientation()
router.dismissCoordinator()
}
}
}