Skip to content

Commit

Permalink
Move reload to separate update block
Browse files Browse the repository at this point in the history
mcudich#9

reloadItems is done separately as the update indexes returne by diff() are in respect to the "after" state, but the collectionView.reloadItems() call wants the "before" indexPaths.
  • Loading branch information
SuperTango committed Feb 7, 2017
1 parent f53df58 commit 488d76d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Source/UICollectionView+Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ public extension UICollectionView {
performBatchUpdates({
self.deleteItems(at: update.deletions)
self.insertItems(at: update.insertions)
self.reloadItems(at: update.updates)
for move in update.moves {
self.moveItem(at: move.from, to: move.to)
}
}, completion: nil)

// reloadItems is done separately as the update indexes returne by diff() are in respect to the
// "after" state, but the collectionView.reloadItems() call wants the "before" indexPaths.
performBatchUpdates({
self.reloadItems(at: update.updates)
}, completion: completion)
}
}
10 changes: 8 additions & 2 deletions Source/UITableView+Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ public extension UITableView {

deleteRows(at: update.deletions, with: animation)
insertRows(at: update.insertions, with: animation)
reloadRows(at: update.updates, with: animation)
for move in update.moves {
moveRow(at: move.from, to: move.to)
}

endUpdates()

// reloadItems is done separately as the update indexes returne by diff() are in respect to the
// "after" state, but the collectionView.reloadItems() call wants the "before" indexPaths.
if update.updates.count > 0 {
beginUpdates()
reloadRows(at: update.updates, with: animation)
endUpdates()
}
}
}

0 comments on commit 488d76d

Please sign in to comment.