From b78b996e88eed32a0e49e6fdd4aa8cf1e5379b07 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 31 Oct 2019 20:55:08 -0500 Subject: [PATCH] Animate Select Feed context menu result. Issue #1220 --- iOS/MasterFeed/MasterFeedViewController.swift | 8 ++++---- .../MasterTimelineViewController.swift | 6 ++++-- iOS/SceneCoordinator.swift | 18 +++++++++++++----- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 7302a40f9..41994f17e 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -129,7 +129,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { guard let feed = notification.userInfo?[UserInfoKey.feed] as? Feed else { return } - discloseFeed(feed) + discloseFeed(feed, animated: true) } @objc func contentSizeCategoryDidChange(_ note: Notification) { @@ -481,7 +481,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } } - func discloseFeed(_ feed: Feed, completion: (() -> Void)? = nil) { + func discloseFeed(_ feed: Feed, animated: Bool, completion: (() -> Void)? = nil) { guard let node = coordinator.rootNode.descendantNodeRepresentingObject(feed as AnyObject) else { completion?() @@ -490,7 +490,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { if let indexPath = dataSource.indexPath(for: node) { tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: true) - coordinator.selectFeed(indexPath) + coordinator.selectFeed(indexPath, animated: animated) completion?() return } @@ -505,7 +505,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { self.applyChanges(animate: true, adjustScroll: true) { [weak self] in if let indexPath = self?.dataSource.indexPath(for: node) { - self?.coordinator.selectFeed(indexPath) + self?.coordinator.selectFeed(indexPath, animated: animated) completion?() } } diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index 61103ed05..4c22bca01 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -586,7 +586,8 @@ private extension MasterTimelineViewController { let title = NSLocalizedString("Select Feed", comment: "Select Feed") let action = UIAction(title: title, image: AppAssets.openInSidebarImage) { [weak self] action in - self?.coordinator.discloseFeed(feed) + self?.coordinator.selectFeed(nil, animated: true) + self?.coordinator.discloseFeed(feed, animated: true) } return action } @@ -596,7 +597,8 @@ private extension MasterTimelineViewController { let title = NSLocalizedString("Select Feed", comment: "Select Feed") let action = UIAlertAction(title: title, style: .default) { [weak self] action in - self?.coordinator.discloseFeed(feed) + self?.coordinator.selectFeed(nil, animated: true) + self?.coordinator.discloseFeed(feed, animated: true) completionHandler(true) } return action diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 10153efe4..1be094103 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -65,6 +65,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { private var lastSearchScope: SearchScope? = nil private var isSearching: Bool = false private var searchArticleIds: Set? = nil + private var isTimelineViewControllerPending = false private var isArticleViewControllerPending = false private(set) var sortDirection = AppDefaults.timelineSortDirection { @@ -782,8 +783,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { markArticlesWithUndo([article], statusKey: .starred, flag: !article.status.starred) } - func discloseFeed(_ feed: Feed, completion: (() -> Void)? = nil) { - masterFeedViewController.discloseFeed(feed) { + func discloseFeed(_ feed: Feed, animated: Bool, completion: (() -> Void)? = nil) { + masterFeedViewController.discloseFeed(feed, animated: animated) { completion?() } } @@ -952,11 +953,15 @@ extension SceneCoordinator: UINavigationControllerDelegate { } // If we are showing the Feeds and only the feeds start clearing stuff - if viewController === masterFeedViewController && !isThreePanelMode { + if viewController === masterFeedViewController && !isThreePanelMode && !isTimelineViewControllerPending { activityManager.invalidateCurrentActivities() selectFeed(nil) return } + + if viewController is MasterTimelineViewController { + isTimelineViewControllerPending = false + } // If we are using a phone and navigate away from the detail, clear up the article resources (including activity). // Don't clear it if we have pushed an ArticleViewController, but don't yet see it on the navigation stack. @@ -1473,6 +1478,9 @@ private extension SceneCoordinator { // MARK: Double Split func installTimelineControllerIfNecessary(animated: Bool) { + + isTimelineViewControllerPending = true + if navControllerForTimeline().viewControllers.filter({ $0 is MasterTimelineViewController }).count < 1 { masterTimelineViewController = UIStoryboard.main.instantiateController(ofType: MasterTimelineViewController.self) masterTimelineViewController!.coordinator = self @@ -1654,7 +1662,7 @@ private extension SceneCoordinator { return } if let feed = feedNode.representedObject as? Feed { - discloseFeed(feed) + discloseFeed(feed, animated: false) } } @@ -1663,7 +1671,7 @@ private extension SceneCoordinator { return } - discloseFeed(feedNode.representedObject as! Feed) { + discloseFeed(feedNode.representedObject as! Feed, animated: false) { guard let articleID = userInfo?[DeepLinkKey.articleID.rawValue] as? String else { return } if let article = self.articles.first(where: { $0.articleID == articleID }) {