Ensure that selected feed is visible when transitioning to three panel mode

This commit is contained in:
Maurice Parker 2019-09-10 16:38:59 -05:00
parent 411413d783
commit aac3c86561
2 changed files with 16 additions and 12 deletions

View File

@ -441,6 +441,16 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
// MARK: API
func restoreSelectionIfNecessary(adjustScroll: Bool) {
if let indexPath = coordinator.masterFeedIndexPathForCurrentTimeline() {
if adjustScroll {
tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: false, deselect: coordinator.isRootSplitCollapsed)
} else {
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
}
}
}
func updateFeedSelection() {
if let indexPath = coordinator.currentFeedIndexPath {
if tableView.indexPathForSelectedRow != indexPath {
@ -500,9 +510,8 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
coordinator.expandFolder(indexPath)
reloadNode(parent)
self.applyChanges(animate: true) { [weak self] in
self.applyChanges(animate: true, adjustScroll: true) { [weak self] in
if let indexPath = self?.coordinator.indexPathFor(node) {
self?.tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
self?.coordinator.selectFeed(indexPath)
completion?()
}
@ -543,11 +552,11 @@ private extension MasterFeedViewController {
var snapshot = dataSource.snapshot()
snapshot.reloadItems([node])
dataSource.apply(snapshot, animatingDifferences: false) { [weak self] in
self?.restoreSelectionIfNecessary()
self?.restoreSelectionIfNecessary(adjustScroll: false)
}
}
func applyChanges(animate: Bool, completion: (() -> Void)? = nil) {
func applyChanges(animate: Bool, adjustScroll: Bool = false, completion: (() -> Void)? = nil) {
var snapshot = NSDiffableDataSourceSnapshot<Int, Node>()
let sections = coordinator.allSections
snapshot.appendSections(sections)
@ -557,7 +566,7 @@ private extension MasterFeedViewController {
}
dataSource.apply(snapshot, animatingDifferences: animate) { [weak self] in
self?.restoreSelectionIfNecessary()
self?.restoreSelectionIfNecessary(adjustScroll: adjustScroll)
completion?()
}
}
@ -636,7 +645,7 @@ private extension MasterFeedViewController {
var snapshot = dataSource.snapshot()
snapshot.reloadItems(nodes)
dataSource.apply(snapshot, animatingDifferences: false) { [weak self] in
self?.restoreSelectionIfNecessary()
self?.restoreSelectionIfNecessary(adjustScroll: false)
}
}
@ -669,12 +678,6 @@ private extension MasterFeedViewController {
self.applyChanges(animate: true)
}
func restoreSelectionIfNecessary() {
if let indexPath = coordinator.masterFeedIndexPathForCurrentTimeline() {
tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: false, deselect: coordinator.isRootSplitCollapsed)
}
}
func makeFeedContextMenu(indexPath: IndexPath, includeDeleteRename: Bool) -> UIContextMenuConfiguration {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { [ weak self] suggestedActions in

View File

@ -1620,6 +1620,7 @@ private extension SceneCoordinator {
let navController = addNavControllerIfNecessary(controller, showButton: false)
subSplitViewController!.showDetailViewController(navController, sender: self)
masterFeedViewController.restoreSelectionIfNecessary(adjustScroll: true)
masterTimelineViewController!.restoreSelectionIfNecessary()
// Return the shim controller