Closed Yurlagin closed 6 years ago
// Perhaps there is a way to be more elegant than this
let changes = diff(old: items, new: viewModel. items)
items = viewModel.items
let insertionsSet = Set(changes.flatMap{$0.insert?.index})
let deletionsSet = Set(changes.flatMap{$0.delete?.index})
let reloadsSet = deletionsSet.intersection(insertionsSet)
let insertions = Array(insertionsSet.filter{!reloadsSet.contains($0)}.map{IndexPath(row: $0, section: 0)})
let deletions = Array(deletionsSet.filter{!reloadsSet.contains($0)}.map{IndexPath(row: $0, section: 0)})
reloadsSet.forEach {
if let cell = tableView.cellForRow(at: IndexPath(row: $0, section: 0)) as? MyCell {
cell.renderUI(event: items[$0])
}
}
tableView.beginUpdates()
tableView.deleteRows(at: deletions, with: .automatic)
tableView.insertRows(at: insertions, with: .automatic)
tableView.endUpdates()
@Yurlagin Hi, sorry for late reply, you can see my response at this issue https://github.com/onmyway133/DeepDiff/issues/16
I need make custom reload cell animation. How can i get reloading indices instead of insertion and deletion pairs?