UICollectionView: Allow for partial invalidation from environment changes

Originator:zach
Number:rdar://27539052 Date Originated:25-Jul-2016 11:35 PM
Status:Open Resolved:false
Product:iOS SDK Product Version:10.0 (14A5309d)
Classification:Enhancement Reproducible:Sometimes
 
Summary:
iOS 8 introduced trait collections and layout margins, externalizing many platform parameters for displaying a view. iOS 10 brings more power to these mechanisms by integrating theming information, like Dynamic Type and Dark Mode, into the fold.

UICollectionViewLayout supports incremental invalidation during a scroll event or in to allow self-sizing, but no other entry points. 

View controllers have all these entry points for environment detection, which is usable only when there's a 1:1 relationship between a collection view controller and the layout of the collection view. This is less tenable when the layout is being reused throughout a codebase.

Steps to Reproduce:
1. Build a collection view layout whose layout data depends on the trait collection or layout margins.
2. Be sad.

Expected Results:
I can perform partial invalidations, like redisplaying all cells, on a trait collection change. I can integrate the code into my layout to prevent code duplication throughout view controllers.

Actual Results:
I can only invalidate during bounds change, which is at best not what I need, and, at worse, a duplicate invalidation to the ones my layout I actually needs.

Version:
iOS 10.0 (14A5309d)

Notes:
Part of this can be done subclassing UICollectionView and giving it a special relationship with its layout, but this isn't feasible for a whole app, or in use with UICollectionViewController.

I was able to accomplish the desired effect with little API consequence by having my custom layout maintain a bounds-sized "canary" decoration view that would call back to the layout.

If it's too late, or not worth considering, to get this approach into the kit, it would be very helpful to describe this technique in docs and/or sample code.

Particularly importance to building this support into the SDK would be disambiguating the callback distinguishing between simple bounds changes, trait-changing bounds changes, and non-bounds trait changes. In my custom layout, a bounds change that causes a trait collection change causes two layout invalidations, and may cause partial data to be rebuilt when not needed. I'll leave that up to you bright folks. :)

Configuration:
iPhone 6s Plus 64GB Verizon, using Wi-Fi

Attachments:

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!