From 31f5e5632a1ce3ad2c0eb6a2ecbc387f421faeab Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 27 Jan 2022 15:26:40 -0800 Subject: [PATCH] Fix how we identify collapsed stack removal for the new 3 panel mode --- iOS/Article/ArticleViewController.swift | 4 ++- iOS/MasterFeed/MasterFeedViewController.swift | 8 +++-- .../MasterTimelineViewController.swift | 5 ++-- iOS/SceneCoordinator.swift | 29 +++++++++++++++---- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 144c1b7a2..f58a490ab 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -12,7 +12,7 @@ import Account import Articles import SafariServices -class ArticleViewController: UIViewController { +class ArticleViewController: UIViewController, MainControllerIdentifiable { typealias State = (extractedArticle: ExtractedArticle?, isShowingExtractedArticle: Bool, @@ -43,6 +43,8 @@ class ArticleViewController: UIViewController { return button }() + var mainControllerIdentifer = MainControllerIdentifier.article + weak var coordinator: SceneCoordinator! private let poppableDelegate = PoppableGestureRecognizerDelegate() diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index a9570e782..3b8faf264 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -13,7 +13,7 @@ import RSCore import RSTree import SafariServices -class MasterFeedViewController: UITableViewController, UndoableCommandRunner { +class MasterFeedViewController: UITableViewController, UndoableCommandRunner, MainControllerIdentifiable { @IBOutlet weak var filterButton: UIBarButtonItem! private var refreshProgressView: RefreshProgressView? @@ -23,9 +23,11 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } } - var undoableCommands = [UndoableCommand]() - weak var coordinator: SceneCoordinator! + var mainControllerIdentifer = MainControllerIdentifier.masterFeed + weak var coordinator: SceneCoordinator! + var undoableCommands = [UndoableCommand]() + private let keyboardManager = KeyboardManager(type: .sidebar) override var keyCommands: [UIKeyCommand]? { diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index f9a8e435b..0c23c472c 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -11,7 +11,7 @@ import RSCore import Account import Articles -class MasterTimelineViewController: UITableViewController, UndoableCommandRunner { +class MasterTimelineViewController: UITableViewController, UndoableCommandRunner, MainControllerIdentifiable { private var numberOfTextLines = 0 private var iconSize = IconSize.medium @@ -27,6 +27,8 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner private lazy var dataSource = makeDataSource() private let searchController = UISearchController(searchResultsController: nil) + var mainControllerIdentifer = MainControllerIdentifier.masterTimeline + weak var coordinator: SceneCoordinator! var undoableCommands = [UndoableCommand]() let scrollPositionQueue = CoalescingQueue(name: "Timeline Scroll Position", interval: 0.3, maxInterval: 1.0) @@ -121,7 +123,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(true) - coordinator.isTimelineViewControllerPending = false if navigationController?.navigationBar.alpha == 0 { UIView.animate(withDuration: 0.5) { diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 596c3522a..b7d1a1f98 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -14,6 +14,17 @@ import RSCore import RSTree import SafariServices +protocol MainControllerIdentifiable { + var mainControllerIdentifer: MainControllerIdentifier { get } +} + +enum MainControllerIdentifier { + case none + case masterFeed + case masterTimeline + case article +} + enum SearchScope: Int { case timeline = 0 case global = 1 @@ -51,11 +62,12 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { private var activityManager = ActivityManager() private var rootSplitViewController: RootSplitViewController! - private var masterFeedViewController: MasterFeedViewController! private var masterTimelineViewController: MasterTimelineViewController? private var articleViewController: ArticleViewController? - + + private var lastMainControllerToAppear = MainControllerIdentifier.none + private let fetchAndMergeArticlesQueue = CoalescingQueue(name: "Fetch and Merge Articles", interval: 0.5) private let rebuildBackingStoresQueue = CoalescingQueue(name: "Rebuild The Backing Stores", interval: 0.5) private var fetchSerialNumber = 0 @@ -72,7 +84,6 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { private var savedSearchArticles: ArticleArray? = nil private var savedSearchArticleIds: Set? = nil - var isTimelineViewControllerPending = false var isArticleViewControllerPending = false private(set) var sortDirection = AppDefaults.shared.timelineSortDirection { @@ -1309,8 +1320,16 @@ extension SceneCoordinator: UINavigationControllerDelegate { return } + defer { + if let mainController = viewController as? MainControllerIdentifiable { + lastMainControllerToAppear = mainController.mainControllerIdentifer + } else if let mainController = (viewController as? UINavigationController)?.topViewController as? MainControllerIdentifiable { + lastMainControllerToAppear = mainController.mainControllerIdentifer + } + } + // If we are showing the Feeds and only the feeds start clearing stuff - if viewController === masterFeedViewController && !isTimelineViewControllerPending { + if viewController === masterFeedViewController && lastMainControllerToAppear == .masterTimeline { activityManager.invalidateCurrentActivities() selectFeed(nil, animations: [.scroll, .select, .navigation]) return @@ -1320,7 +1339,7 @@ extension SceneCoordinator: UINavigationControllerDelegate { // Don't clear it if we have pushed an ArticleViewController, but don't yet see it on the navigation stack. // This happens when we are going to the next unread and we need to grab another timeline to continue. The // ArticleViewController will be pushed, but we will briefly show the Timeline. Don't clear things out when that happens. - if viewController === masterTimelineViewController && !isArticleViewControllerPending { + if viewController === masterTimelineViewController && lastMainControllerToAppear == .article && !isArticleViewControllerPending { currentArticle = nil masterTimelineViewController?.updateArticleSelection(animations: [.scroll, .select, .navigation]) activityManager.invalidateReading()