Fix crash from reloading of existing story cell when inserting new cell above it

This commit is contained in:
Harry Sanabria 2022-10-12 13:13:15 -07:00 committed by Nora Trapp
parent 62553c9f51
commit f0cb7bc558

View File

@ -607,9 +607,9 @@ class StoryListDataSource: NSObject, Dependencies {
case .move(let oldIndex, let newIndex):
tableView.deleteRows(at: [IndexPath(row: oldIndex, section: section.rawValue)], with: .fade)
tableView.insertRows(at: [IndexPath(row: newIndex, section: section.rawValue)], with: .fade)
case .update(_, let newIndex):
case .update(let oldIndex, let newIndex):
// If the cell is visible, reconfigure it directly without reloading.
let path = IndexPath(row: newIndex, section: section.rawValue)
let path = IndexPath(row: oldIndex, section: section.rawValue)
if
(tableView.indexPathsForVisibleRows ?? []).contains(path),
let visibleCell = tableView.cellForRow(at: path) as? StoryCell