UICollectionViewLayout should document relationship between invalidateLayout() and invalidateLayout(with:)

Originator:eric.s.blair
Number:rdar://40218744 Date Originated:14-May-2018 11:55 AM
Status:Open Resolved:
Product:iOS + SDK Product Version:iOS 11
Classification:UI/Usability Reproducible:Always
 
Summary:
This is primary a documentation issue, but right now there doesn’t appear to be anything in the class/method documentation for UICollectionViewLayout to indicate that `.invalidateLayout` and `invalidateLayout(with:)` are called in the same path

Without this info, it can lead developers of custom layouts to implement both `invalidateLayout()` and `invalidateLayout(with:)`, thinking that the former can be called when a full invalidation is required and that the latter can be used for targeted invalidation.

Since it’s actually that the former calls the latter, this can lead to inadvertently clearing layout attributes at unnecessary times and lead to performance issues

Steps to Reproduce:
1. Create a UICollectionViewLayout subclass
2. Implement invalidateLayout() such that it clears all attributes
3. Implement invalidateLayout(with:) such that it clears some of the attributes as appropriate
4. Implement shouldInvalidateLayout(forBoundsChange:) to return true
4. Display a collection view with the custom layout and change the bounds

Expected Results:
From the documentation, it’s not entirely clear if both invalidateLayout() and invalidateLayout(with:) will be called

Actual Results:
Both invalidateLayout() and invalidateLayout(with:) are called, losing the performance gains of doing the targeted invalidation.

Version:
iOS 11

Notes:
The “Optimizing Layout Performance Using Invalidation Contexts” section of the documentation _almost_ makes this clear.

https://developer.apple.com/documentation/uikit/uicollectionviewlayout

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!