UICollectionViewFlowLayout incorrect delete animation

Originator:kellerbryan19
Number:rdar://41492798 Date Originated:06/26/2018
Status:Closed Resolved:Yes
Product:UIKit Product Version:iOS 12
Classification:Bug Reproducible:Yes
 
Summary:
Once rdar://41101885 (https://openradar.appspot.com/radar?id=5006149438930944) is fixed (`UICollectionView` providing preferred attributes for old index paths during a delete batch update, which results in an index OOB crash on iOS 11 and iOS 12 b1 and b2), there will still be an animation issue:

When an unsized, offscreen item slides up into view due to an item delete above it, the item will animate with its estimated height, rather than its final height, despite layout attributes with the correct, final height being returned from `initialLayoutAttributesForAppearingItem` and `finalLayoutAttributesForDisappearingItem` throughout the animation.

Note that I'm assuming the correct attributes are being returned from those functions once rdar://41101885 is fixed. I can confirm on my own self sizing layout that I return the correct attributes here, but the animation is still wrong.

It appears that even after all items in the collection view have received their final sizes, the cell that's sliding up onto screen will receive old, stale layout attributes (with an estimated height) several times via `apply(_ layoutAttributes: UICollectionViewLayoutAttributes)`. Basically, it never has the chance to update to its final height before collection view calls `snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? ` for the animation.


Steps to Reproduce:
1. Open attached sample project. 
2. Click "Append" 3 times to add 3 items, one of which will be offscreen below the fold.
3. Click "Remove at 0" to do a batch update delete for the first item

Observe that the offscreen item that moved from {0, 2} -> {0, 1} will animate in with an estimated height, then snap to its final height as soon as the animation ends.

Expected Results:
The cell should be snapshotted after updating to its preferred height.

Actual Results:
The cell is snapshotted when it only has its estimated height.

Version/Build:
iOS 12 b3, assuming rdar://41101885 (https://openradar.appspot.com/radar?id=5006149438930944) is fixed. On iOS 11 and iOS 12 b1 and b2, it'll just crash so you won't even get to see the animation.


Sample project: https://drive.google.com/file/d/1hUzkqaNU5ii9QAZiEfTA1fliAy40HdQT/view?usp=sharing

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!