Merge pull request #412 from RyanRory/home-refresh-crash

Fix tableView.endUpdates() Crash
pull/417/head
Niels Andriesse 3 years ago committed by GitHub
commit c91a2ae7dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -226,12 +226,26 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
switch rowChange.type {
case .delete: tableView.deleteRows(at: [ rowChange.indexPath! ], with: UITableView.RowAnimation.automatic)
case .insert: tableView.insertRows(at: [ rowChange.newIndexPath! ], with: UITableView.RowAnimation.automatic)
case .move: tableView.moveRow(at: rowChange.indexPath!, to: rowChange.newIndexPath!)
case .update: tableView.reloadRows(at: [ rowChange.indexPath! ], with: UITableView.RowAnimation.automatic)
default: break
}
}
tableView.endUpdates()
// HACK: Moves can have conflicts with other 3 types of change.
// Just batch perform all the moves seperately to prevent crashing.
// Since all the changes are from original state to final state,
// it will still be correct if we pick the Moves out.
tableView.beginUpdates()
rowChanges.forEach { rowChange in
let rowChange = rowChange as! YapDatabaseViewRowChange
let key = rowChange.collectionKey.key
threadViewModelCache[key] = nil
switch rowChange.type {
case .move: tableView.moveRow(at: rowChange.indexPath!, to: rowChange.newIndexPath!)
default: break
}
}
tableView.endUpdates()
emptyStateView.isHidden = (threadCount != 0)
}

Loading…
Cancel
Save