Items get messed up when sections are added
rablador opened this issue · 4 comments
Scrolling and reusing items seems to work fine when there are no sections present, but as soon as I add one, the list get laggy and jumpy. Also, the second section somehow overlaps some of the items.
The code (in a view, inside awakeFromNib):
manager.registerHeader(TimeHeader.self) { $0.condition = .section(0) } manager.registerHeader(TimeSectionHeader.self) { $0.condition = .section(1) } storage.setSectionHeaderModel(TimeHeaderModel(), forSection: 0) storage.setSectionHeaderModel(TimeSectionHeaderModel(timeDay: .monday), forSection: 1)
Then I'm simply adding models to storage as usual.
Alright, I think I found it. Setting sectionHeadersPinToVisibleBounds
on flow layout is what messes things up. Any workaround for sticky headers?
Sorry, i did not use sectionHeadersPinToVisibleBounds
, so not really sure what is going on there. Maybe you can dig into it more? Maybe items are laggy not because of headers, but because of complex layouts?
Well, it seems setting estimatedItemSize
on the flow layout was the specific cause of the problem. I guess the collection view got messed up while trying to calculate all items and adding sections in-between. Calculating the size manually in manager.sizeForCell()
did the trick.
Haven't tested sticky headers before, so there's a possibility that DTCollectionViewManager isn't at fault here. Could be worth testing vanilla collection view delegates sometime to see what's what.
I saw a problem with estimated sizes where layout did become jumpy when estimated size was smaller then cells after proper layouts. One possible fix that worked for me was increasing estimated size to always be bigger than most of the cells, and layout becomes much more stable.
That's not related to DTCollectionViewManager
itself, but something to keep in mind. I will close this issue for now, since it's related to UICollectionViewFlowLayout
and not this framework. Please reopen or open a new one if you find any issues in flow layout handling by DTCollectionViewManager
. Thanks!