From ca0bdb3d35dac2dbf6dd51d4d38256b84378a361 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 30 Aug 2019 14:42:33 -0500 Subject: [PATCH] Change to not animate on timeline fetcher changes --- iOS/AppCoordinator.swift | 16 ++++++++-------- .../MasterTimelineViewController.swift | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/iOS/AppCoordinator.swift b/iOS/AppCoordinator.swift index f80568f9c..08df4595a 100644 --- a/iOS/AppCoordinator.swift +++ b/iOS/AppCoordinator.swift @@ -156,7 +156,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } var currentArticle: Article? { - if let indexPath = currentArticleIndexPath { + if let indexPath = currentArticleIndexPath, indexPath.row < articles.count { return articles[indexPath.row] } return nil @@ -165,7 +165,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { private(set) var currentArticleIndexPath: IndexPath? { didSet { if currentArticleIndexPath != oldValue { - masterTimelineViewController?.updateArticleSelection() + masterTimelineViewController?.updateArticleSelection(animate: true) detailViewController?.updateArticleSelection() } } @@ -184,7 +184,6 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } updateShowAvatars() articleRowMap = [String: Int]() - masterTimelineViewController?.reloadArticles() updateUnreadCount() } } @@ -883,14 +882,15 @@ private extension AppCoordinator { } func sortDirectionDidChange() { - replaceArticles(with: Set(articles)) + replaceArticles(with: Set(articles), animate: true) } - func replaceArticles(with unsortedArticles: Set
) { + func replaceArticles(with unsortedArticles: Set
, animate: Bool) { let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection) if articles != sortedArticles { let article = currentArticle articles = sortedArticles + masterTimelineViewController?.reloadArticles(animate: animate) if let articleID = article?.articleID, let index = indexForArticleID(articleID) { currentArticleIndexPath = IndexPath(row: index, section: 0) } @@ -936,7 +936,7 @@ private extension AppCoordinator { } } - strongSelf.replaceArticles(with: updatedArticles) + strongSelf.replaceArticles(with: updatedArticles, animate: true) } } @@ -957,7 +957,7 @@ private extension AppCoordinator { return } let fetchedArticles = fetchUnsortedArticlesSync(for: [timelineFetcher]) - replaceArticles(with: fetchedArticles) + replaceArticles(with: fetchedArticles, animate: false) } func fetchAndReplaceArticlesAsync(completion: @escaping () -> Void) { @@ -969,7 +969,7 @@ private extension AppCoordinator { return } fetchUnsortedArticlesAsync(for: [timelineFetcher]) { [weak self] (articles) in - self?.replaceArticles(with: articles) + self?.replaceArticles(with: articles, animate: false) completion() } } diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index b23af9961..47ffe820c 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -119,16 +119,16 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner reloadAllVisibleCells() } - func reloadArticles() { - applyChanges(animate: true) { [weak self] in - self?.updateArticleSelection() + func reloadArticles(animate: Bool) { + applyChanges(animate: animate) { [weak self] in + self?.updateArticleSelection(animate: animate) } } - func updateArticleSelection() { + func updateArticleSelection(animate: Bool) { if let indexPath = coordinator.currentArticleIndexPath { if tableView.indexPathForSelectedRow != indexPath { - tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle) + tableView.selectRow(at: indexPath, animated: animate, scrollPosition: .middle) } } updateUI()