Skip to content

Commit

Permalink
Merge pull request #14 from composed-swift/potential-fix-for-crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephDuffy authored Nov 16, 2020
2 parents 8ee5b11 + f14dd9f commit cc1d8e4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/ComposedUI/CollectionView/CollectionCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ extension CollectionCoordinator: SectionProviderMappingDelegate {
public func mappingWillBeginUpdating(_ mapping: SectionProviderMapping) {
reset()
defersUpdate = true

// This is called here to ensure that the collection view's internal state is in-sync with the state of the
// data in hierarchy of sections. If this is not done it can cause various crashes when `performBatchUpdates` is called
// due to the collection view requesting data for sections that no longer exist, or crashes because the collection view is
// told to delete/insert from/into sections that it does not yet think exist.
//
// For more information on this see https://github.com/composed-swift/ComposedUI/pull/14
collectionView.layoutIfNeeded()
}

public func mappingDidEndUpdating(_ mapping: SectionProviderMapping) {
Expand Down

0 comments on commit cc1d8e4

Please sign in to comment.