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
Large Navbars #48
Comments
CollectionView always invalidate's its layout when its size changes. The reason being that some layouts are calculated from the collectionView's size. I understand that there are situations like this where one of the axis is not used and might change frequently. For Try the following layout: public class FixedSizedLayout<Data>: CollectionLayout<Data> {
var cellHeight: CGFloat = 84
var spacing: CGFloat = 10
var collectionWidth: CGFloat = 0
var numberOfItems: Int = 0
public override func layout(collectionSize: CGSize,
dataProvider: CollectionDataProvider<Data>,
sizeProvider: @escaping (Int, Data, CGSize) -> CGSize) {
// store the following information necessary when calculating cell frame and contentSize
numberOfItems = dataProvider.numberOfItems
collectionWidth = collectionSize.width
}
public final override var contentSize: CGSize {
return CGSize(width: collectionWidth,
height: CGFloat(numberOfItems) * (cellHeight + spacing) - spacing)
}
public final override func frame(at: Int) -> CGRect {
return CGRect(x: 0, y: CGFloat(at) * (cellHeight + spacing),
width: collectionWidth, height: cellHeight)
}
public override func visibleIndexes(activeFrame: CGRect) -> [Int] {
let minIndex = Int(activeFrame.minY / (cellHeight + spacing))
let maxIndex = Int(activeFrame.maxY / (cellHeight + spacing))
return Array(minIndex...maxIndex)
}
} Note that layout is very optimized. No matter how many cell you have it will always calculate in O(1) time. |
@lkzhao Your suggestion works really well with one section (as you mentioned) but I actually want to use multiple sections in the CollectionView. While trying I ran into multiple issues when using a CollectionComposer:
Any suggestions how to use this tweaked solution with multiple Provider? |
Hmm weird. Are you using any shared CollectionProvider, CollectionViewProvider, or layout by any chance? |
What do you mean with shared? They are all only used in one CollectionComposer and used by one CollectionView. Sent with GitHawk |
@lkzhao Do you need a sample project to look for yourself? |
@Narsail Yes that would be great. |
Please reopen if you are still experiencing problem. Also try updating to the latest v2. |
Is the SizeProvider called for every data object in the Data Provider when the Collection View Size is changing? I have around 1300 items in my data and when using the Large Navigationbars the scrolling is seriously stuttering.
I checked what the source of the stuttering might be and I found that the sizeProvider of every cell is called every time when the size of the collectionView changes. That might be the culprit.
See the Example:
The text was updated successfully, but these errors were encountered: