Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ public protocol CollectionViewDataProvider: AnyObject {

public extension CollectionViewDataProvider {
func isValid(indexPath: IndexPath) -> Bool {
numberOfSections > indexPath.section
&& numberOfItems(inSection: indexPath.section) > indexPath.row
let section = indexPath.section
let item = indexPath.item

guard section >= 0, item >= 0 else {
return false
}

guard section < numberOfSections else {
return false
}

return item < numberOfItems(inSection: section)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class OffsetControllerImpl: OffsetController {

let previousVisibleFrame = previousVisibleAttributes[visibleState.targetIndexPath] ?? .zero

for item in updates {
for item in updates where isSane(updateItem: item) {
visibleStateController.update(with: item)
}

Expand All @@ -115,6 +115,23 @@ public class OffsetControllerImpl: OffsetController {
return calculatedOffsetDiff
}

private func isSane(updateItem: CollectionViewUpdateItem) -> Bool {
isSane(indexPath: updateItem.indexPathBeforeUpdate, isSection: updateItem.isSection)
&& isSane(indexPath: updateItem.indexPathAfterUpdate, isSection: updateItem.isSection)
}

private func isSane(indexPath: IndexPath?, isSection: Bool) -> Bool {
guard let indexPath else {
return true
}

if isSection {
return indexPath.section >= 0 && indexPath.item == Int.max
}

return indexPath.section >= 0 && indexPath.item >= 0
}

private func refreshVisibleState() {
guard let collectionDataSource = collectionDataSource else {
return
Expand Down
Loading