Skip to content
Open

Fix #21

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
7 changes: 6 additions & 1 deletion CardsCollectionViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ open class CardsCollectionViewLayout: UICollectionViewLayout {
override open func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let totalItemsCount = collectionView.numberOfItems(inSection: 0)

let minVisibleIndex = max(Int(collectionView.contentOffset.x) / Int(collectionView.bounds.width), 0)
var minVisibleIndex = max(Int(collectionView.contentOffset.x) / Int(collectionView.bounds.width), 0)
let maxVisibleIndex = min(minVisibleIndex + maximumVisibleItems, totalItemsCount)

let contentCenterX = collectionView.contentOffset.x + (collectionView.bounds.width / 2.0)
Expand All @@ -59,6 +59,11 @@ open class CardsCollectionViewLayout: UICollectionViewLayout {

let percentageDeltaOffset = CGFloat(deltaOffset) / collectionView.bounds.width

// ToDO: fix crash
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove todo please?

if minVisibleIndex > totalItemsCount {
minVisibleIndex = totalItemsCount
}
Comment on lines +63 to +65
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why minVisibleIndex could be larger than totalItemsCount ? Does this happen when collectionView.contentOffset.x is too large? Could it be that the real root cause is in the different place?


let visibleIndices = stride(from: minVisibleIndex, to: maxVisibleIndex, by: 1)

let attributes: [UICollectionViewLayoutAttributes] = visibleIndices.map { index in
Expand Down