diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 8cce3fe0a..192852858 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -497,6 +497,9 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers 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 } diff --git a/SessionUIKit/Components/TopBannerController.swift b/SessionUIKit/Components/TopBannerController.swift index f00e53115..a9cc5108e 100644 --- a/SessionUIKit/Components/TopBannerController.swift +++ b/SessionUIKit/Components/TopBannerController.swift @@ -95,11 +95,7 @@ public class TopBannerController: UIViewController { view.addSubview(contentStackView) contentStackView.addArrangedSubview(bannerContainer) - - child.willMove(toParent: self) - addChild(child) - contentStackView.addArrangedSubview(child.view) - child.didMove(toParent: self) + attachChild() bannerContainer.addSubview(bannerLabel) bannerContainer.addSubview(closeButton) @@ -155,6 +151,13 @@ public class TopBannerController: UIViewController { // 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) { guard Thread.isMainThread else { DispatchQueue.main.async { diff --git a/SessionUIKit/Style Guide/ThemeManager.swift b/SessionUIKit/Style Guide/ThemeManager.swift index a38356ebb..766d533ef 100644 --- a/SessionUIKit/Style Guide/ThemeManager.swift +++ b/SessionUIKit/Style Guide/ThemeManager.swift @@ -1,4 +1,6 @@ // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved. +// +// stringlint:disable import UIKit import GRDB @@ -203,7 +205,7 @@ public enum ThemeManager { func updateIfNeeded(viewController: UIViewController?) { guard let viewController: UIViewController = viewController else { return } guard - let navController: UINavigationController = ((viewController as? UINavigationController) ?? viewController.navigationController), + let navController: UINavigationController = retrieveNavigationController(from: viewController), let superview: UIView = navController.view.superview, !navController.isNavigationBarHidden else { @@ -218,9 +220,19 @@ public enum ThemeManager { applyNavigationStylingIfNeeded(to: viewController) // Re-attach to the UI - navController.view.removeFromSuperview() - superview.addSubview(navController.view) + let wasFirstResponder: Bool = (navController.topViewController?.isFirstResponder == true) + + switch navController.parent { + case let topBannerController as TopBannerController: + navController.view.removeFromSuperview() + topBannerController.attachChild() + + default: + navController.view.removeFromSuperview() + superview.addSubview(navController.view) + } navController.topViewController?.setNeedsStatusBarAppearanceUpdate() + if wasFirstResponder { navController.topViewController?.becomeFirstResponder() } // Recurse through the rest of the UI 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() { guard Thread.isMainThread else { return DispatchQueue.main.async { applyWindowStyling() }