UICollectionView with self-sizing cells resets cells to estimatedSize during insert/remove animation

Originator:Roland.Leth
Number:rdar://35717256 Date Originated:November 28, 2017
Status: Resolved:No
Product:UIKit Product Version:11.1.2
Classification:Serious bug Reproducible:Always
 
Summary:

Given a UICollectionView that makes use of self-sizing cells, when items are inserted or removed, the cells resize to and render (!) at the estimated size before rendering at the correct size, causing flickers onscreen.

Steps to Reproduce:

Create a UICollectionView whose cells use Auto Layout and that override preferredLayoutAttributesFitting. Set an estimatedItemSize on the UICollectionViewFlowLayout, e.g. layout.estimatedItemSize = CGSize(width: 100, 1).

Insert or delete (or both) items into the UICollectionView, e.g.

collectionView.performBatchUpdates({
    self.collectionView.insertItems(at: indexPaths)
}, completion: nil)

Expected Results:
When inserting/deleting items, the cells maintain their size.

Actual Results:
Cells reset to their estimated size before expanding back to their actual size, causing a loss of contentOffset and weird scrolling artefacts.

Extra info:
Even if I set CATransaction.setDisableActions(true) before the batch update, there is still a split second during which the cells are rendered at their estimatedSize, meaning there's a flicker on screen. This means there's no way to use self-sizing cells if insertion/deletion is required/desired.

Attached you can find a demo project.

Version:
iOS 11.1.2

Comments


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!