Iglistkit: The position of the scroll indicator when prepending data

Created on 15 Apr 2017  路  8Comments  路  Source: Instagram/IGListKit

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?

question

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:

  • Get the topmost visible cell's frame using the UICollectionViewLayout
  • performUpdates(animated: false)
  • In the completion block, find the same cell's frame via UICollectionViewLayout
  • Calculate the delta between the old and new frame, apply to contentOffset

All 8 comments

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:

  • Get the topmost visible cell's frame using the UICollectionViewLayout
  • performUpdates(animated: false)
  • In the completion block, find the same cell's frame via UICollectionViewLayout
  • Calculate the delta between the old and new frame, apply to contentOffset

Oh 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kanumuri9593 picture kanumuri9593  路  3Comments

FazeelAkhtar picture FazeelAkhtar  路  3Comments

iwasrobbed picture iwasrobbed  路  3Comments

runmad picture runmad  路  3Comments

alexwillrock picture alexwillrock  路  3Comments