I have a view that is like the comments system in instagram, where the newest data appears at the bottom of the collection view. As I scroll up, I get the next page of data and call performUpdates() to prepend the new data to my existing data. However, when the collection view adds on this extra data, the scroll indicator is still right at the top of the collection view instead of at the bottom of the new data. This can be visualised like this:
UICollectionView cells with data:
- data <- Scroll indicator scrolled to the top of the collectionview and new data starts to load
- data
- data
- data <- Scroll indicator starts here at the bottom of the collectionview
Scrolling up does this:
- new data <- Scroll indicator stays at the top and the new data is inserted
- new data
- new data
- new data
- data
- data
- data
- data
However it should look like this:
- new data
- new data
- new data
- new data
- data <- Scroll indicator
- data
- data
- data
How can I change that?
Tracking this in #242 right now. We do this in Instagram in a few places and are planning on open sourcing how we do it, just lower priority atm. If you want to get it working ASAP:
UICollectionViewLayoutperformUpdates(animated: false)UICollectionViewLayoutcontentOffsetOh yes!! Thank you :)
@yusuftor not sure if you manage to solve your problem, but you can check my approach, which doesn't require to save visible cell here.
Thanks @darrarski! I couldn't get it to work the way Ryan said, so instead I calculated the difference in contentSize before and after the update and applied that to the contentOffset. I will also try your way to see if it's any better :)
Any updates on this issue?
I'm able to scroll to the correct offset but it always has a little stutter/visual glitch.
@pkuklis Do u solve the stutter/visual glitch issue. I implement in the same way above and also have glitch issue. Cannot figure out how to solve it.
@pkuklis Do u solve the stutter/visual glitch issue. I implement in the same way above and also have glitch issue. Cannot figure out how to solve it.
Unfortunately not
@pkuklis found the solution
https://github.com/Instagram/IGListKit/issues/242#issuecomment-501904367
This is the promising way to maintain scroll position without pain.
Most helpful comment
Tracking this in #242 right now. We do this in Instagram in a few places and are planning on open sourcing how we do it, just lower priority atm. If you want to get it working ASAP:
UICollectionViewLayoutperformUpdates(animated: false)UICollectionViewLayoutcontentOffset