Restore the feed selection if an account containing the selection is expanded

This commit is contained in:
Maurice Parker
2019-09-03 13:59:22 -05:00
parent b7ba2c809c
commit e6a4338a86
2 changed files with 17 additions and 3 deletions

View File

@@ -469,8 +469,6 @@ private extension MasterFeedViewController {
}
func applyChanges(animate: Bool, completion: (() -> Void)? = nil) {
let savedNode = selectedNode()
var snapshot = NSDiffableDataSourceSnapshot<Int, Node>()
let sections = coordinator.allSections
snapshot.appendSections(sections)
@@ -480,7 +478,7 @@ private extension MasterFeedViewController {
}
dataSource.apply(snapshot, animatingDifferences: animate) { [weak self] in
self?.selectRow(node: savedNode)
self?.restoreSelectionIfNecessary()
completion?()
}
}
@@ -605,6 +603,15 @@ private extension MasterFeedViewController {
self.applyChanges(animate: true)
}
func restoreSelectionIfNecessary() {
guard traitCollection.userInterfaceIdiom == .pad else {
return
}
if let indexPath = coordinator.masterFeedIndexPathForCurrentTimeline(), indexPath != tableView.indexPathForSelectedRow {
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
}
}
func makeFeedContextMenu(indexPath: IndexPath, includeDeleteRename: Bool) -> UIContextMenuConfiguration {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { [ weak self] suggestedActions in

View File

@@ -467,6 +467,13 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
animatingChanges = false
}
func masterFeedIndexPathForCurrentTimeline() -> IndexPath? {
guard let node = treeController.rootNode.descendantNode(where: { return $0.representedObject === timelineFetcher as AnyObject }) else {
return nil
}
return indexPathFor(node)
}
func indexForArticleID(_ articleID: String?) -> Int? {
guard let articleID = articleID else { return nil }
updateArticleRowMapIfNeeded()