wordpress-mobile / MediaPicker-iOS

WPMediaPicker is an iOS controller that allows capture and picking of media assets.
GNU General Public License v2.0
110 stars 37 forks source link

Add support for custom header views #379

Closed frosty closed 2 years ago

frosty commented 2 years ago

This PR adds support for custom header views in the media picker collection view. This will be used in WordPress-iOS to show an info panel at the top of the picker if a user has only provided limited access to their photo library.

Three methods have been added to the media picker delegate protocol:

These in combination allow a delegate to control whether a custom header view is displayed, configure the view if necessary before it's displayed, and provide a reference size which will be used to display the view at the correct size.

In order for these to have an effect, the custom header type must be registered using a new method on WPMediaPickerViewController: registerClassForCustomHeaderView(_:). The class must be a subclass of UICollectionReusableView.

I've added an option to the demo app to show an example custom header:

Simulator Screen Shot - iPhone 13 Pro - 2022-01-11 at 22 54 00 Simulator Screen Shot - iPhone 13 Pro - 2022-01-11 at 22 54 09

There are a few small caveats around the current implementation:

To test

frosty commented 2 years ago

Thanks for the comment @SergioEstevao! So in the case where a camera capture header and a custom header are enabled, only the custom header will display.

In my upcoming PR for WordPress-iOS, I've only added the permissions alert to screens that don't currently use the capture cell – Media Library +, Gutenberg, Stories. In the other areas, we could just add "Take a photo" to the action sheet that appears before displaying the media picker and not use the capture cell there any more. This may actually be clearer for the user and is would be more consistent across the app.