From 8497b7bdcdf4266832c35e431d373f0bc3f477ef Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 5 Oct 2022 16:43:31 -0500 Subject: [PATCH] Fix split view controller unread indicator launch visibility --- iOS/Article/ArticleViewController.swift | 50 ++++++++++--------------- iOS/SceneCoordinator.swift | 2 +- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 0615c8158..a12370ba6 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -87,6 +87,8 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { return keyboardManager.keyCommands } + private var lastKnownDisplayMode: UISplitViewController.DisplayMode? + var currentUnreadCount: Int = 0 { didSet { updateUnreadCountIndicator() @@ -342,37 +344,6 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { configureAppearanceMenu() } - - /// Updates the indicator count in the navigation bar. - /// For iPhone, this indicator is visible if the unread count is > 0. - /// For iPad, this indicator is visible if it is in `portrait` or `unknown` - /// orientation, **and** the unread count is > 0. - /// - Parameter sender: `Any` (optional) - public func updateUnreadCountIndicator(forDisplayMode displayMode: UISplitViewController.DisplayMode? = nil) { - func changeUnreadCountIndicator() { - if currentUnreadCount > 0 { - let unreadCountView = MasterTimelineUnreadCountView(frame: .zero) - unreadCountView.unreadCount = currentUnreadCount - unreadCountView.setFrameIfNotEqual(CGRect(x: 0, y: 0, width: unreadCountView.intrinsicContentSize.width, height: unreadCountView.intrinsicContentSize.height)) - navigationItem.leftBarButtonItem = UIBarButtonItem(customView: unreadCountView) - } else { - navigationItem.leftBarButtonItem = nil - } - } - - if UIDevice.current.userInterfaceIdiom == .phone { - changeUnreadCountIndicator() - } else { - if displayMode == nil || displayMode == .secondaryOnly { - changeUnreadCountIndicator() - } else { - navigationItem.leftBarButtonItem = nil - } - } - } - - - // MARK: Notifications @objc dynamic func unreadCountDidChange(_ notification: Notification) { @@ -480,6 +451,12 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { func setScrollPosition(isShowingExtractedArticle: Bool, articleWindowScrollY: Int) { currentWebViewController?.setScrollPosition(isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) } + + public func splitViewControllerWillChangeTo(displayMode: UISplitViewController.DisplayMode) { + lastKnownDisplayMode = displayMode + updateUnreadCountIndicator() + } + } // MARK: Find in Article @@ -638,4 +615,15 @@ private extension ArticleViewController { return controller } + func updateUnreadCountIndicator() { + if currentUnreadCount > 0 && (traitCollection.userInterfaceIdiom == .phone || lastKnownDisplayMode == .secondaryOnly) { + let unreadCountView = MasterTimelineUnreadCountView(frame: .zero) + unreadCountView.unreadCount = currentUnreadCount + unreadCountView.setFrameIfNotEqual(CGRect(x: 0, y: 0, width: unreadCountView.intrinsicContentSize.width, height: unreadCountView.intrinsicContentSize.height)) + navigationItem.leftBarButtonItem = UIBarButtonItem(customView: unreadCountView) + } else { + navigationItem.leftBarButtonItem = nil + } + } + } diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 8dd9e2e49..103200a22 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -1324,7 +1324,7 @@ extension SceneCoordinator: UISplitViewControllerDelegate { } func splitViewController(_ svc: UISplitViewController, willChangeTo displayMode: UISplitViewController.DisplayMode) { - articleViewController?.updateUnreadCountIndicator(forDisplayMode: displayMode) + articleViewController?.splitViewControllerWillChangeTo(displayMode: displayMode) } }