UICollectionView.contentSize is wrong with self-sizing cells and non-default minimumLineSpacing

Originator:an00na
Number:rdar://46944818 Date Originated:December 25 2018, 9:43 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:12.1
Classification:Serious Bug Reproducible:Always
 
Area:
UIKit

Summary:
For a horizontal scrolling UICollectionView with UICollectionViewFlowLayout, its contentSize is wrong with self-sizing cells if collectionViewLayout.minimumLineSpacing is not the default value(which is 10 currently).

Steps to Reproduce:
1. Launch sample app on iPhone SE simulator.
2. Scroll to the end to see that the last cell is cut off because the contentSize is tool small.
3. Tap Change button on top.
4. Scroll to the end to see that there is a large margin on the right because the contentSize is too large.
5. minimumLineSpacing in code to 10 to see the correct behavior.

Code: https://mega.nz/#!NCJAAIib!ivlcU6gSE1I2yAg2m9txmo0hkoZ23dovRtyC_uHUFF8

Comments

The actual bug

Thanks a lot an00na for your bug report in the first place, it oriented me toward the proper solution. As of iOS 15, the bug is still present (and it was already present on iOS 11).

However, the actual bug is that: - the layout uses minimumLineSpacing for displaying - but it uses minimumInteritemSpacing for computing the contentSize.

The solution is therefore to set both to the same value. It explains why you were misled thinking it only works when minimumLineSpacing is 10: that is the default value of minimumInteritemSpacing.

By renaud.pradenc at Nov. 5, 2021, 1:23 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com 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!