From 762710266d8c08e1ab4e893ca663e86542209ce7 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 30 Aug 2019 16:19:06 -0500 Subject: [PATCH] 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. --- iOS/MasterFeed/MasterFeedViewController.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 563ffc9db..c54695caa 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -393,6 +393,11 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { func reloadFeeds() { updateUI() 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) { @@ -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? { if let account = node.representedObject as? Account { return account