Fix status bar not hiding

This commit is contained in:
Shadowfacts 2023-01-14 13:24:29 -05:00
parent 73ab213631
commit 07f8d8e89e
4 changed files with 48 additions and 9 deletions

View File

@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
<key>NSUserActivityTypes</key> <key>NSUserActivityTypes</key>
<array> <array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.activate-account</string> <string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.activate-account</string>

View File

@ -12,6 +12,14 @@ class AppNavigationController: UINavigationController, UINavigationControllerDel
private var statusBarBlockingView: UIView! private var statusBarBlockingView: UIView!
static let panRecognizerName = "AppNavPanRecognizer" static let panRecognizerName = "AppNavPanRecognizer"
override var childForStatusBarHidden: UIViewController? {
topViewController
}
override var childForStatusBarStyle: UIViewController? {
topViewController
}
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@ -44,7 +52,12 @@ class AppNavigationController: UINavigationController, UINavigationControllerDel
} }
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) { func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
statusBarBlockingView.isHidden = viewController.prefersStatusBarHidden statusBarBlockingView.layer.opacity = viewController.prefersStatusBarHidden ? 0 : 1
}
override func setNeedsStatusBarAppearanceUpdate() {
super.setNeedsStatusBarAppearanceUpdate()
statusBarBlockingView?.layer.opacity = childForStatusBarHidden!.prefersStatusBarHidden ? 0 : 1
} }
private var poppingViewController: UIViewController? private var poppingViewController: UIViewController?

View File

@ -17,6 +17,14 @@ class AppSplitViewController: UISplitViewController {
private var secondaryNav: UINavigationController! private var secondaryNav: UINavigationController!
override var childForStatusBarHidden: UIViewController? {
if traitCollection.horizontalSizeClass == .compact {
return viewController(for: .compact)
} else {
return nil
}
}
init(fervorController: FervorController) { init(fervorController: FervorController) {
self.fervorController = fervorController self.fervorController = fervorController

View File

@ -30,12 +30,14 @@ class ReadViewController: UIViewController {
private var webView: WKWebView! private var webView: WKWebView!
#if targetEnvironment(macCatalyst)
private var itemReadObservation: NSKeyValueObservation?
#endif
override var prefersStatusBarHidden: Bool { override var prefersStatusBarHidden: Bool {
navigationController?.isNavigationBarHidden ?? false if navigationController?.isNavigationBarHidden == true,
let webView,
webView.scrollView.contentOffset.y > -webView.scrollView.safeAreaInsets.top {
return true
} else {
return false
}
} }
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
@ -98,6 +100,18 @@ class ReadViewController: UIViewController {
activityItemsConfiguration = UIActivityItemsConfiguration(objects: [url as NSURL]) activityItemsConfiguration = UIActivityItemsConfiguration(objects: [url as NSURL])
} }
webView.scrollView.publisher(for: \.contentOffset)
.map { [unowned self] _ in
self.prefersStatusBarHidden
}
.removeDuplicates()
.sink { [unowned self] _ in
UIView.animate(withDuration: 0.2, delay: 0) {
self.setNeedsStatusBarAppearanceUpdate()
}
}
.store(in: &cancellables)
scrollPositionChangedSubject scrollPositionChangedSubject
.debounce(for: .milliseconds(500), scheduler: RunLoop.main) .debounce(for: .milliseconds(500), scheduler: RunLoop.main)
.sink { [unowned self] in .sink { [unowned self] in
@ -106,9 +120,11 @@ class ReadViewController: UIViewController {
.store(in: &cancellables) .store(in: &cancellables)
#if targetEnvironment(macCatalyst) #if targetEnvironment(macCatalyst)
itemReadObservation = item.observe(\.read) { [unowned self] _, _ in item.publisher(for: \.read)
self.updateToggleReadToolbarImage() .sink { [unowned self] _ in
} self.updateToggleReadToolbarImage()
}
.store(in: &cancellables)
#endif #endif
} }