auto-landscape rotate, overlay fade in/out, and appearance setting fix

This commit is contained in:
Ethan Pippin 2021-12-30 03:13:02 -07:00
parent 01e52e59b7
commit 604f41bffd
3 changed files with 30 additions and 18 deletions

View File

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

View File

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

View File

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