Skip to content

Invalidate the cache for bounds only if the size has changed #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2018
Merged
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
8 changes: 7 additions & 1 deletion Sources/CollectionViewSlantedLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ import UIKit
internal var cachedAttributes = [CollectionViewSlantedLayoutAttributes]()
/// :nodoc:
internal var cachedContentSize: CGFloat = 0
/// :nodoc:
internal var currentSize: CGSize = CGSize.zero

/// :nodoc:
fileprivate func itemSize(forItemAt indexPath: IndexPath) -> (value: CGFloat, isDynamic: Bool) {
Expand Down Expand Up @@ -215,6 +217,7 @@ import UIKit
cachedAttributes = [CollectionViewSlantedLayoutAttributes]()
cachedContentSize = 0
}

}

// MARK: CollectionViewLayout methods overriding
Expand All @@ -231,6 +234,9 @@ extension CollectionViewSlantedLayout {

/// :nodoc:
override open func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
guard newBounds.size != currentSize else {
return false
}
invalidateCache()
return true
}
Expand All @@ -241,8 +247,8 @@ extension CollectionViewSlantedLayout {
return
}

currentSize = collectionView?.bounds.size ?? CGSize.zero
let staticMasks = calculatedMasks(itemSize: max(itemSize, 0))

var position: CGFloat = 0

for item in 0..<numberOfItems {
Expand Down