Fixed an issue where theme changes stopped updating nav styling

pull/924/head
Morgan Pretty 9 months ago
parent 6d57523ede
commit 3a9ada581d

@ -497,6 +497,9 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
startObservingChanges() startObservingChanges()
/// If the view is removed and readded to the view hierarchy then `viewWillDisappear` will be called but `viewDidDisappear`
/// **won't**, as a result `viewIsDisappearing` would never get set to `false` - do so here to handle this case
viewIsDisappearing = false
viewIsAppearing = true viewIsAppearing = true
} }

@ -95,11 +95,7 @@ public class TopBannerController: UIViewController {
view.addSubview(contentStackView) view.addSubview(contentStackView)
contentStackView.addArrangedSubview(bannerContainer) contentStackView.addArrangedSubview(bannerContainer)
attachChild()
child.willMove(toParent: self)
addChild(child)
contentStackView.addArrangedSubview(child.view)
child.didMove(toParent: self)
bannerContainer.addSubview(bannerLabel) bannerContainer.addSubview(bannerLabel)
bannerContainer.addSubview(closeButton) bannerContainer.addSubview(closeButton)
@ -155,6 +151,13 @@ public class TopBannerController: UIViewController {
// MARK: - Functions // MARK: - Functions
public func attachChild() {
child.willMove(toParent: self)
addChild(child)
contentStackView.addArrangedSubview(child.view)
child.didMove(toParent: self)
}
public static func show(warning: Warning, inWindowFor view: UIView? = nil) { public static func show(warning: Warning, inWindowFor view: UIView? = nil) {
guard Thread.isMainThread else { guard Thread.isMainThread else {
DispatchQueue.main.async { DispatchQueue.main.async {

@ -1,4 +1,6 @@
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved. // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
//
// stringlint:disable
import UIKit import UIKit
import GRDB import GRDB
@ -203,7 +205,7 @@ public enum ThemeManager {
func updateIfNeeded(viewController: UIViewController?) { func updateIfNeeded(viewController: UIViewController?) {
guard let viewController: UIViewController = viewController else { return } guard let viewController: UIViewController = viewController else { return }
guard guard
let navController: UINavigationController = ((viewController as? UINavigationController) ?? viewController.navigationController), let navController: UINavigationController = retrieveNavigationController(from: viewController),
let superview: UIView = navController.view.superview, let superview: UIView = navController.view.superview,
!navController.isNavigationBarHidden !navController.isNavigationBarHidden
else { else {
@ -218,9 +220,19 @@ public enum ThemeManager {
applyNavigationStylingIfNeeded(to: viewController) applyNavigationStylingIfNeeded(to: viewController)
// Re-attach to the UI // Re-attach to the UI
navController.view.removeFromSuperview() let wasFirstResponder: Bool = (navController.topViewController?.isFirstResponder == true)
superview.addSubview(navController.view)
switch navController.parent {
case let topBannerController as TopBannerController:
navController.view.removeFromSuperview()
topBannerController.attachChild()
default:
navController.view.removeFromSuperview()
superview.addSubview(navController.view)
}
navController.topViewController?.setNeedsStatusBarAppearanceUpdate() navController.topViewController?.setNeedsStatusBarAppearanceUpdate()
if wasFirstResponder { navController.topViewController?.becomeFirstResponder() }
// Recurse through the rest of the UI // Recurse through the rest of the UI
updateIfNeeded(viewController: updateIfNeeded(viewController:
@ -263,6 +275,16 @@ public enum ThemeManager {
} }
} }
private static func retrieveNavigationController(from viewController: UIViewController) -> UINavigationController? {
switch viewController {
case let navController as UINavigationController: return navController
case let topBannerController as TopBannerController:
return (topBannerController.children.first as? UINavigationController)
default: return viewController.navigationController
}
}
public static func applyWindowStyling() { public static func applyWindowStyling() {
guard Thread.isMainThread else { guard Thread.isMainThread else {
return DispatchQueue.main.async { applyWindowStyling() } return DispatchQueue.main.async { applyWindowStyling() }

Loading…
Cancel
Save