Skip to content

Commit

Permalink
Improve status bar height initial value (#838)
Browse files Browse the repository at this point in the history
* Improve PDFReaderViewController code

* Improve PDFReaderViewController statusBarHeight initial value
  • Loading branch information
mvasilak authored Feb 2, 2024
1 parent 9edb197 commit b47f037
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PDFReaderViewController: UIViewController {
private var previousTraitCollection: UITraitCollection?
var isSidebarVisible: Bool { return self.sidebarControllerLeft?.constant == 0 }
var key: String { return self.viewModel.state.key }
var statusBarHeight: CGFloat
var statusBarHeight: CGFloat = .zero
var navigationBarHeight: CGFloat {
return self.navigationController?.navigationBar.frame.height ?? 0.0
}
Expand Down Expand Up @@ -182,18 +182,6 @@ class PDFReaderViewController: UIViewController {
self.viewModel = viewModel
self.isCompactWidth = compactSize
self.disposeBag = DisposeBag()
self.statusBarHeight = UIApplication
.shared
.connectedScenes
.filter({ $0.activationState == .foregroundActive })
.compactMap({ $0 as? UIWindowScene })
.first?
.windows
.first(where: { $0.isKeyWindow })?
.windowScene?
.statusBarManager?
.statusBarFrame
.height ?? 0
super.init(nibName: nil, bundle: nil)
}

Expand All @@ -204,6 +192,8 @@ class PDFReaderViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

statusBarHeight = (view.scene as? UIWindowScene)?.statusBarManager?.statusBarFrame.height ?? .zero

self.set(userActivity: .pdfActivity(for: self.viewModel.state.key, libraryId: self.viewModel.state.library.identifier, collectionId: Defaults.shared.selectedCollectionId))

self.view.backgroundColor = .systemGray6
Expand Down Expand Up @@ -741,7 +731,7 @@ extension PDFReaderViewController: AnnotationToolbarDelegate {
return self.isCompactWidth ? documentController.view.frame.size.width : (documentController.view.frame.size.width - (2 * AnnotationToolbarHandler.toolbarFullInsetInset))

case .trailing, .leading:
let window = (view.scene as? UIWindowScene)?.windows.first(where: \.isKeyWindow)
let window = (view.scene as? UIWindowScene)?.keyWindow
let topInset = window?.safeAreaInsets.top ?? 0
let bottomInset = window?.safeAreaInsets.bottom ?? 0
let interfaceIsHidden = self.navigationController?.isNavigationBarHidden ?? false
Expand Down Expand Up @@ -816,8 +806,7 @@ extension PDFReaderViewController: PDFDocumentDelegate {
self.annotationToolbarHandler.interfaceVisibilityDidChange()

UIView.animate(withDuration: 0.15, animations: {
self.navigationController?.setNeedsStatusBarAppearanceUpdate()
self.setNeedsStatusBarAppearanceUpdate()
self.updateStatusBar()
self.view.layoutIfNeeded()
if shouldChangeNavigationBarVisibility {
self.navigationController?.navigationBar.alpha = isHidden ? 0 : 1
Expand Down

0 comments on commit b47f037

Please sign in to comment.