Self Sizing + Prefetching Bugs

Number:rdar://40926834 Date Originated:6/8/2018
Status:Open Resolved:No
Product:UIKit Product Version:iOS 12
Classification:Bug Reproducible:Yes

UICollectionView has glitchy scrolling issues and cell sizing issues when 
- isPrefetchingEnabled == true
- a UICollectionViewLayout subclass that self-sizes cells is used (but not a UICollectionViewFlowLayout subclass). 

The issue occurs specifically when in the aforementioned scenario, and scrolling up to rubber band / over scroll at the top immediately after the collection view loads. When the user lets go and the over scrolled collection view begins to rubber band back *toward* contentOffset.y == 0 (the final resting state at the top), the contentOffset.y will be briefly set to 0 *during the rubber band animation* - which causes the collection view to jump to offset 0 in the middle of the animation. This is very jarring and noticeable.

Attached is a demo project with a UI test to simulate this over scroll behavior reliably and consistently. See Steps to Reproduce.

Steps to Reproduce:
1. Open sample project. The included project is set to use a simple, self sizing layout by default (subclass of UICollectionViewLayout).
2. Command+U to run the UI test, which will simulate an over scroll at the top in a consistent way each time the test is run.
3. Note the jumpiness. If it's not obvious, re-run the UI test a few more times.

Ways to "fix" the issue:
-  ViewController.swift:24, switch to using flow layout.
- ViewController.swift:44, set isPrefetchingEnabled to false.
- SelfSizingLayout.swift:26, override _estimatesSizes and return true. The code is already there, so just uncomment it at the top.

Expected Results:
The user should be able to over scroll at the top without jumpy animations. No special internal flags should be needed to achieve correct behavior.

Actual Results:
The over scroll animation at the top is jumpy, due to a mix of prefetching and self sizing cells.

iOS 11 (and 12)

Demo project:


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!