diff --git a/Sources/LiveCollections/Classes/Internal/ItemDataCalculator.swift b/Sources/LiveCollections/Classes/Internal/ItemDataCalculator.swift index d2a6245..b9ea549 100644 --- a/Sources/LiveCollections/Classes/Internal/ItemDataCalculator.swift +++ b/Sources/LiveCollections/Classes/Internal/ItemDataCalculator.swift @@ -204,8 +204,14 @@ private extension ItemDataCalculator { } self?._performNextCalculation() } - - guard delta.hasChanges else { + + let isDeltaAccurate: Bool = (itemProvider.items.count + delta.insertions.count - delta.deletions.count) == updatedItems.count + + if isDeltaAccurate == false { + calculationDelegate?.inaccurateDeltaDetected(delta) + } + + guard delta.hasChanges, isDeltaAccurate else { updateData() calculationCompletion() return diff --git a/Sources/LiveCollections/Classes/Internal/SectionDataCalculator.swift b/Sources/LiveCollections/Classes/Internal/SectionDataCalculator.swift index 44cb8db..172bf5e 100644 --- a/Sources/LiveCollections/Classes/Internal/SectionDataCalculator.swift +++ b/Sources/LiveCollections/Classes/Internal/SectionDataCalculator.swift @@ -274,8 +274,16 @@ private extension SectionDataCalculator { } return } - - guard sectionDelta.hasChanges || itemDelta.hasChanges else { + + let currentItemCount: Int = sectionProvider.sections.reduce(0) { $0 + $1.items.count } + let updatedItemCount: Int = updatedSections.reduce(0) { $0 + $1.items.count } + let isDeltaAccurate: Bool = (currentItemCount + itemDelta.insertions.count - itemDelta.deletions.count) == updatedItemCount + + if isDeltaAccurate == false { + self.calculationDelegate?.inaccurateDeltaDetected(itemDelta) + } + + guard (sectionDelta.hasChanges || itemDelta.hasChanges), isDeltaAccurate else { sectionProvider.calculatingSections = nil calculationCompletion() return // don't need to update with no changes diff --git a/Sources/LiveCollections/Classes/Public/Delegate/CollectionDataDelegate.swift b/Sources/LiveCollections/Classes/Public/Delegate/CollectionDataDelegate.swift index 4024036..f762434 100644 --- a/Sources/LiveCollections/Classes/Public/Delegate/CollectionDataDelegate.swift +++ b/Sources/LiveCollections/Classes/Public/Delegate/CollectionDataDelegate.swift @@ -65,6 +65,7 @@ public protocol CollectionDataCalculationNotificationDelegate: AnyObject { func collectionDataDidBeginCalculating() func collectionDataDidEndCalculating() + func inaccurateDeltaDetected(_ delta: IndexDelta) } // MARK: CollectionDataAnimationDelegate