-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate PHPickerViewController in Page Editor #21360
Conversation
import WordPressShared | ||
import WPMediaPicker | ||
import Gutenberg | ||
import UniformTypeIdentifiers | ||
|
||
public typealias GutenbergMediaPickerHelperCallback = ([WPMediaAsset]?) -> Void | ||
public typealias GutenbergMediaPickerHelperCallback = ([Any]?) -> Void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am specifically not using the WPMediaAsset
protocol because it’s part of the MediaPicker repo and is designed for displaying images in the picker’s collection view cells, but it ended up being used as a marker protocol in multiple places of the app. The goal is to remove the MediaPicker dependency entirely.
@@ -154,9 +180,6 @@ class GutenbergMediaInserterHelper: NSObject { | |||
} | |||
|
|||
func syncUploads() { | |||
if mediaObserverReceipt != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicates the code from #21352 because these changes need to be tested together.
📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
|
I'm going to bump this to the next release because we'll be code freezing 23.1 today and this hasn't been approved yet. If this cannot wait two weeks and it's important that it makes it into this release, let me know and we'll organize a new beta once ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as described
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I've tested different cases using the Gutenberg editor and the new media picker. Users will benefit from this so much 🚀 Nice work!
I test drove this as well and it looked great! 🚀 Thank you @kean. |
Part of #21190.
The changes affect both the WP and the Jetpack app.
Simulator.Screen.Recording.-.iPad.Air.5th.generation.-.2023-08-17.at.11.51.23.mp4
Tests
Important
For additional test cases, see #21343. It covers the picker and the media uploads at great lengths. But there should be no need to repeat them because this PR builds on top of these changes.
[Tech] Preview URL
When the media is added to one of the Gutenberg blocks, it expects a URL. But the app has no URLs at the time the user makes a selection in the native picker.
In the current implementation, when you select the assets, the editor first requests their previews using
PHImageManager.default().requestImage
and.fastFormat
and only then updates the Gutenberg blocks. It achieves that when the blocks are updated, the images already have previews, but it comes at a great cost.The requested thumbnails are usually very small: example (120 ×90px), but with the next line
thumbImage.resizedImage(asset.pixelSize()
, the editor blows it up to the original image size: example (4032 × 3024px) and puts them on disk in the temporary folder. There are many problems with it:MediaImportService
does to export the images and generate the previews (work duplication)As a result, the app ends up wasting a ton of CPU, RAM, and disk space just to show previews that almost immediately (a few hundred milliseconds later) get replaced by
MediaImportService
in the following callback:The solution I went with in this PR was to not generate the thumbnails at all and just pass placeholder URLs that point to nothing. It dramatically reduces the memory footprint and there is no delay after the selection is made in the picker:
The previews get displayed as soon as the
MediaImportService
generates them.Regression Notes
PR submission checklist:
RELEASE-NOTES.txt
if necessary.UI Changes testing checklist: