Reload all cells when a batch update completes because we might be out of sync even though we called apply on the datasource. This can happen when moving a feed into and out of a folder.

This commit is contained in:
Maurice Parker 2019-08-30 16:19:06 -05:00
parent ca0bdb3d35
commit 762710266d
1 changed files with 16 additions and 0 deletions

View File

@ -393,6 +393,11 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
func reloadFeeds() { func reloadFeeds() {
updateUI() updateUI()
applyChanges(animate: true) applyChanges(animate: true)
// We have to reload all the visible cells because if we got here by doing a table cell move,
// then the table itself is in a weird state. This is because we do unusual things like allowing
// drops on a "folder" that should cause the dropped cell to disappear.
reloadAllVisibleCells()
} }
func discloseFeed(_ feed: Feed) { func discloseFeed(_ feed: Feed) {
@ -556,6 +561,17 @@ private extension MasterFeedViewController {
} }
} }
private func reloadAllVisibleCells() {
let visibleNodes = tableView.indexPathsForVisibleRows!.compactMap { return coordinator.nodeFor($0) }
reloadCells(visibleNodes)
}
private func reloadCells(_ nodes: [Node]) {
var snapshot = dataSource.snapshot()
snapshot.reloadItems(nodes)
dataSource.apply(snapshot, animatingDifferences: false)
}
private func accountForNode(_ node: Node) -> Account? { private func accountForNode(_ node: Node) -> Account? {
if let account = node.representedObject as? Account { if let account = node.representedObject as? Account {
return account return account