From 68608390d27f2ee4535a810ef4e61d002b20caa5 Mon Sep 17 00:00:00 2001 From: Michael Sergienko Date: Fri, 7 Aug 2020 11:43:01 +0300 Subject: [PATCH 1/2] Fix --- CardsCollectionViewLayout.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CardsCollectionViewLayout.swift b/CardsCollectionViewLayout.swift index d82d4c8..c287fbd 100644 --- a/CardsCollectionViewLayout.swift +++ b/CardsCollectionViewLayout.swift @@ -59,6 +59,11 @@ open class CardsCollectionViewLayout: UICollectionViewLayout { let percentageDeltaOffset = CGFloat(deltaOffset) / collectionView.bounds.width + // ToDO: fix crash + if minVisibleIndex > totalItemsCount { + minVisibleIndex = totalItemsCount + } + let visibleIndices = stride(from: minVisibleIndex, to: maxVisibleIndex, by: 1) let attributes: [UICollectionViewLayoutAttributes] = visibleIndices.map { index in From f9ea1ae7140d398fe53761955358e96a19a67182 Mon Sep 17 00:00:00 2001 From: Michael Sergienko Date: Fri, 7 Aug 2020 12:02:45 +0300 Subject: [PATCH 2/2] Fix --- CardsCollectionViewLayout.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CardsCollectionViewLayout.swift b/CardsCollectionViewLayout.swift index c287fbd..b7b8295 100644 --- a/CardsCollectionViewLayout.swift +++ b/CardsCollectionViewLayout.swift @@ -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)