From a6f6462afd964fb32a8ac5b78d2a945170c07037 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 6 Sep 2019 13:45:45 -0500 Subject: [PATCH] Make arrow key scrolling work like it does on the Mac timeline --- iOS/MasterFeed/MasterFeedViewController.swift | 10 +++-- .../MasterTimelineViewController.swift | 45 ++++++------------- iOS/SceneCoordinator.swift | 10 ++--- submodules/RSCore | 2 +- 4 files changed, 26 insertions(+), 41 deletions(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 13feab1bb..22de11c04 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -97,8 +97,10 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { node = coordinator.rootNode.descendantNodeRepresentingObject(representedObject as AnyObject) } - if let node = node, coordinator.indexPathFor(node) != nil { - reloadNode(node) + if let node = node, let indexPath = coordinator.indexPathFor(node), let unreadCountProvider = node.representedObject as? UnreadCountProvider { + if let cell = tableView.cellForRow(at: indexPath) as? MasterFeedTableViewCell { + cell.unreadCount = unreadCountProvider.unreadCount + } } } @@ -437,7 +439,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } if let indexPath = coordinator.currentFeedIndexPath { if tableView.indexPathForSelectedRow != indexPath { - tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle) + tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: true) } } else { tableView.selectRow(at: nil, animated: true, scrollPosition: .none) @@ -667,7 +669,7 @@ private extension MasterFeedViewController { return } if let indexPath = coordinator.masterFeedIndexPathForCurrentTimeline(), indexPath != tableView.indexPathForSelectedRow { - tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none) + tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: false) } } diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index a612490e6..170a6151e 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -162,7 +162,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner if let indexPath = coordinator.currentArticleIndexPath { if tableView.indexPathForSelectedRow != indexPath { - tableView.selectRow(at: indexPath, animated: animate, scrollPosition: .middle) + tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: true) } } else { tableView.selectRow(at: nil, animated: animate, scrollPosition: .none) @@ -307,10 +307,20 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner } @objc func statusesDidChange(_ note: Notification) { - guard let articles = note.userInfo?[Account.UserInfoKey.articles] as? Set
else { + guard let updatedArticles = note.userInfo?[Account.UserInfoKey.articles] as? Set
else { return } - reloadVisibleCells(for: articles) + + let visibleArticles = tableView.indexPathsForVisibleRows!.map { return coordinator.articles[$0.row] } + let visibleUpdatedArticles = visibleArticles.filter { updatedArticles.contains($0) } + + for article in visibleUpdatedArticles { + if let articleIndex = coordinator.indexForArticleID(article.articleID) { + if let cell = tableView.cellForRow(at: IndexPath(row: articleIndex, section: 0)) as? MasterTimelineTableViewCell { + configure(cell, article: article) + } + } + } } @objc func feedIconDidBecomeAvailable(_ note: Notification) { @@ -381,33 +391,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner reloadCells(visibleArticles) } - private func reloadVisibleCells(for articles: [Article]) { - reloadVisibleCells(for: Set(articles.articleIDs())) - } - - private func reloadVisibleCells(for articles: Set
) { - reloadVisibleCells(for: articles.articleIDs()) - } - - private func reloadVisibleCells(for articleIDs: Set) { - if articleIDs.isEmpty { - return - } - let indexes = coordinator.indexesForArticleIDs(articleIDs) - reloadVisibleCells(for: indexes) - } - - private func reloadVisibleCells(for indexes: IndexSet) { - let reloadArticles: [Article] = tableView.indexPathsForVisibleRows!.compactMap { indexPath in - if indexes.contains(indexPath.row) { - return coordinator.articles[indexPath.row] - } else { - return nil - } - } - reloadCells(reloadArticles) - } - private func reloadCells(_ articles: [Article]) { var snapshot = dataSource.snapshot() snapshot.reloadItems(articles) @@ -560,7 +543,7 @@ private extension MasterTimelineViewController { } if let articleID = coordinator.currentArticle?.articleID, let index = coordinator.indexForArticleID(articleID) { let indexPath = IndexPath(row: index, section: 0) - tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none) + tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: false) } } diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 3fc78544a..46856d69f 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -579,6 +579,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { selectArticle(nil) currentFeedIndexPath = indexPath + masterFeedViewController.updateFeedSelection() + if let ip = indexPath, let node = nodeFor(ip), let fetcher = node.representedObject as? ArticleFetcher { timelineFetcher = fetcher updateSelectingActivity(with: node) @@ -596,7 +598,6 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } } - masterFeedViewController.updateFeedSelection() } func selectPrevFeed() { @@ -633,10 +634,6 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { currentArticleIndexPath = indexPath activityManager.reading(currentArticle) - if let article = currentArticle { - markArticles(Set([article]), statusKey: .read, flag: true) - } - if indexPath == nil { if rootSplitViewController.isCollapsed { if masterNavigationController.children.last is DetailViewController { @@ -670,6 +667,9 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { detailViewController?.updateArticleSelection() + if let article = currentArticle { + markArticles(Set([article]), statusKey: .read, flag: true) + } } func beginSearching() { diff --git a/submodules/RSCore b/submodules/RSCore index 50cf102ac..75b609926 160000 --- a/submodules/RSCore +++ b/submodules/RSCore @@ -1 +1 @@ -Subproject commit 50cf102acd0592ec3bff2446f19386b6593e1ff8 +Subproject commit 75b609926fe64c7c14428a39bda1f301cd968f46