UICollectionView scrolls back to 0 using comp layout

PLATFORM AND VERSION:

  • iOS

Development environment:

  • Xcode 15.2
  • macOS 13.6.3
  • iOS 17.2

DESCRIPTION OF PROBLEM

Using a UICollectionView with compositional layout, once the view is created, programmatically scroll to a row using the scrollToItem method.

  • For this report I created a simple dataSource with 400 rows and 1 section.
  • Scrolling to row 200 in viewDidLoad or viewWillAppear after calling collectionView.layoutIfNeeded().
  • The compositional layout's orthogonalScrollingBehavior is set to .groupPagingCentered

The collectionView behaves as expected and shows row 200.

Issue

The issue is that when swiping too quickly to go to row 199 or prior the entire collectionView is reset to row 0. This does not happen when swiping to go on row 201 or above.

STEPS TO REPRODUCE

  • Run the app on iPhone.
  • Swipe right quickly (to go to row prior to 200)
  • Expected result: row 199 or 198 is shown
  • Actual result: collectionView is reset to row 0
Answered by Frameworks Engineer in 792543022

Thank you for providing sample code! I can confirm that this indeed is a bug and we are looking to resolve the issue.

Attaching an example here. For some reason Apple does not allow to attach a zip of the Xcode example project.

Thank you for providing sample code! I can confirm that this indeed is a bug and we are looking to resolve the issue.

@Frameworks Engineer Could you please suggest a solution? Is there perhaps an alternative approach you could recommend? Thank you in advance for your answer.

@adrienyvon, have you found any other solution?

UICollectionView scrolls back to 0 using comp layout
 
 
Q