From 604f41bffd37b05b369aba8f26d59ab0af800c4d Mon Sep 17 00:00:00 2001 From: Ethan Pippin Date: Thu, 30 Dec 2021 03:13:02 -0700 Subject: [PATCH] auto-landscape rotate, overlay fade in/out, and appearance setting fix --- JellyfinPlayer/App/JellyfinPlayerApp.swift | 9 ++++- .../VideoPlayer/VLCPlayerViewController.swift | 37 +++++++++++-------- .../iOSVideoPlayerCoordinator.swift | 2 + 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/JellyfinPlayer/App/JellyfinPlayerApp.swift b/JellyfinPlayer/App/JellyfinPlayerApp.swift index 3d11e057..88d6880a 100644 --- a/JellyfinPlayer/App/JellyfinPlayerApp.swift +++ b/JellyfinPlayer/App/JellyfinPlayerApp.swift @@ -19,8 +19,11 @@ struct JellyfinPlayerApp: App { var body: some Scene { WindowGroup { - MainCoordinator().view() + EmptyView() .ignoresSafeArea() + .withHostingWindow({ window in + window?.rootViewController = PreferenceUIHostingController(wrappedView: MainCoordinator().view()) + }) .onAppear { setupAppearance() } @@ -34,7 +37,9 @@ struct JellyfinPlayerApp: App { } private func setupAppearance() { - UIApplication.shared.windows.first?.overrideUserInterfaceStyle = appAppearance.style + let scenes = UIApplication.shared.connectedScenes + let windowScene = scenes.first as? UIWindowScene + windowScene?.windows.first?.overrideUserInterfaceStyle = appAppearance.style } } diff --git a/JellyfinPlayer/Views/VideoPlayer/VLCPlayerViewController.swift b/JellyfinPlayer/Views/VideoPlayer/VLCPlayerViewController.swift index c028052c..d2648ca6 100644 --- a/JellyfinPlayer/Views/VideoPlayer/VLCPlayerViewController.swift +++ b/JellyfinPlayer/Views/VideoPlayer/VLCPlayerViewController.swift @@ -85,14 +85,6 @@ class VLCPlayerViewController: UIViewController { ]) } - // MARK: viewWillAppear - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - -// AppUtility.lockOrientation(.all, andRotateTo: .landscapeLeft) - } - // MARK: viewWillDisappear override func viewWillDisappear(_ animated: Bool) { @@ -102,8 +94,6 @@ class VLCPlayerViewController: UIViewController { defaultNotificationCenter.removeObserver(self, name: UIApplication.willTerminateNotification, object: nil) defaultNotificationCenter.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil) defaultNotificationCenter.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil) - -// AppUtility.lockOrientation(.all) } // MARK: viewDidLoad @@ -209,13 +199,19 @@ class VLCPlayerViewController: UIViewController { // MARK: setupOverlayHostingController private func setupOverlayHostingController(viewModel: VideoPlayerViewModel) { - + + // TODO: Look at injecting viewModel into the environment so it updates the current overlay if let currentOverlayHostingController = currentOverlayHostingController { - currentOverlayHostingController.view.isHidden = true - - currentOverlayHostingController.view.removeFromSuperview() - currentOverlayHostingController.removeFromParent() - self.currentOverlayHostingController = nil + // UX fade-out + UIView.animate(withDuration: 0.5) { + currentOverlayHostingController.view.alpha = 0 + } completion: { _ in + currentOverlayHostingController.view.isHidden = true + + currentOverlayHostingController.view.removeFromSuperview() + currentOverlayHostingController.removeFromParent() +// self.currentOverlayHostingController = nil + } } let newOverlayView = VLCPlayerCompactOverlayView(viewModel: viewModel) @@ -223,6 +219,10 @@ class VLCPlayerViewController: UIViewController { newOverlayHostingController.view.translatesAutoresizingMaskIntoConstraints = false newOverlayHostingController.view.backgroundColor = UIColor.clear + + // UX fade-in + newOverlayHostingController.view.alpha = 0 + addChild(newOverlayHostingController) view.addSubview(newOverlayHostingController.view) newOverlayHostingController.didMove(toParent: self) @@ -234,6 +234,11 @@ class VLCPlayerViewController: UIViewController { newOverlayHostingController.view.rightAnchor.constraint(equalTo: videoContentView.rightAnchor) ]) + // UX fade-in + UIView.animate(withDuration: 0.5) { + newOverlayHostingController.view.alpha = 1 + } + self.currentOverlayHostingController = newOverlayHostingController // There is a behavior when setting this that the navigation bar diff --git a/Shared/Coordinators/VideoPlayerCoordinator/iOSVideoPlayerCoordinator.swift b/Shared/Coordinators/VideoPlayerCoordinator/iOSVideoPlayerCoordinator.swift index 494901d3..f15a8b63 100644 --- a/Shared/Coordinators/VideoPlayerCoordinator/iOSVideoPlayerCoordinator.swift +++ b/Shared/Coordinators/VideoPlayerCoordinator/iOSVideoPlayerCoordinator.swift @@ -34,6 +34,7 @@ final class VideoPlayerCoordinator: NavigationCoordinatable { .statusBar(hidden: true) .ignoresSafeArea() .prefersHomeIndicatorAutoHidden(true) + .supportedOrientations(.landscape) }.ignoresSafeArea() } else { PreferenceUIHostingControllerView { @@ -42,6 +43,7 @@ final class VideoPlayerCoordinator: NavigationCoordinatable { .statusBar(hidden: true) .ignoresSafeArea() .prefersHomeIndicatorAutoHidden(true) + .supportedOrientations(.landscape) }.ignoresSafeArea() } }