diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 12ce2aa90..0615c8158 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -102,7 +102,6 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(reloadDueToThemeChange(_:)), name: .CurrentArticleThemeDidChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(configureAppearanceMenu(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(updateUnreadCountIndicator(_:)), name: UIDevice.orientationDidChangeNotification, object: nil) articleExtractorButton.addTarget(self, action: #selector(toggleArticleExtractor(_:)), for: .touchUpInside) toolbarItems?.insert(UIBarButtonItem(customView: articleExtractorButton), at: 6) @@ -349,9 +348,8 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { /// For iPad, this indicator is visible if it is in `portrait` or `unknown` /// orientation, **and** the unread count is > 0. /// - Parameter sender: `Any` (optional) - @objc - public func updateUnreadCountIndicator(_ sender: Any? = nil) { - if UIDevice.current.userInterfaceIdiom == .phone { + public func updateUnreadCountIndicator(forDisplayMode displayMode: UISplitViewController.DisplayMode? = nil) { + func changeUnreadCountIndicator() { if currentUnreadCount > 0 { let unreadCountView = MasterTimelineUnreadCountView(frame: .zero) unreadCountView.unreadCount = currentUnreadCount @@ -360,17 +358,13 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { } else { navigationItem.leftBarButtonItem = nil } + } + + if UIDevice.current.userInterfaceIdiom == .phone { + changeUnreadCountIndicator() } else { - - if UIDevice.current.orientation.isPortrait || !UIDevice.current.orientation.isValidInterfaceOrientation { - 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 displayMode == nil || displayMode == .secondaryOnly { + changeUnreadCountIndicator() } else { navigationItem.leftBarButtonItem = nil } diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 1c5c8dec6..8dd9e2e49 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -1323,6 +1323,10 @@ extension SceneCoordinator: UISplitViewControllerDelegate { } } + func splitViewController(_ svc: UISplitViewController, willChangeTo displayMode: UISplitViewController.DisplayMode) { + articleViewController?.updateUnreadCountIndicator(forDisplayMode: displayMode) + } + } // MARK: UINavigationControllerDelegate