-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: GutenbergKit Media Library support #23721
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
Conversation
A single Media Library callback resulted in erroneously mutating unselected blocks.
Unable to recreate the original erroneously replacement of media attachments for unselected blocks. This now feels unnecessary.
Address lint warning.
Enable retaining selection for gallery addition/editing in the block editor.
Reusing the `initialSelection` reduces complexity.
This no longer disrupts initial selection as the setting the initial selection now occurs within `setEditing` rather than initialization.
This appears to be unnecessary with the latest implementation.
Without returning the initial selection, canceling cleared out media attached to Gallery blocks in the web-based editor, as it presumes the existing media will be returned as "selected."
Workaround existing logic that dismisses the dialog if `allowMuliple` is true and selection is not empty. The existing logic allows for quickly selecting a single media item, but inhibits the ability to showcase a pre-existing selection for single-select contexts. This diverges from the web experience, but is the easiest path forward to avoid a significant refactor of the logic that would impact all other existing use cases--Gutenberg Mobile, Aztec, etc.
Map the Media lookup results to the original array of media IDs so that the sort order is preserved.
Generated by 🚫 Danger |
|
| App Name | WordPress Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr23721-48be44a | |
| Version | 25.4 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 48be44a | |
| App Center Build | WPiOS - One-Offs #11028 |
|
| App Name | Jetpack Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr23721-48be44a | |
| Version | 25.4 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 48be44a | |
| App Center Build | jetpack-installable-builds #10067 |
| if let selectedMedia = initialSelection, allowsMultipleSelection { | ||
| setInitialSelection(selectedMedia) | ||
| } else { | ||
| deselectAll() | ||
| } |
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.
In order to support an initial selection for Gallery blocks—which is required by the web Gallery block implementation—we must now conditionally deselect all. Retaining an initial selection also improves the UX.
The restriction of initial selections to allowsMultipleSelection diverges from the web Media Library experience, but is a workaround for the native Media Library's current implementation that dismisses the dialog when a selection exists and multiple is disallowed.
The native approach creates a flow where tapping an image selects and dismisses the dialog for single-select contexts, reducing the number of taps to complete the flow. Rather than attempting a larger change to modify this behavior and align with web, I disabled initial selection when multiple selection is disabled—i.e., any block besides a Gallery.
|
|
||
| private func buttonCancelTapped() { | ||
| delegate?.siteMediaPickerViewController(self, didFinishWithSelection: []) | ||
| delegate?.siteMediaPickerViewController(self, didFinishWithSelection: initialSelection) |
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.
Given initialSelection should be [] outside of the specific context of the "new" Gutenberg, this change should, in theory, have no negative impact on existing use case—e.g., Gutenberg Mobile, Aztec.
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 approach was copied and adapted from GutenbergViewController.
| .showSiteMediaPicker(blog: post.blog, delegate: self) | ||
| } | ||
|
|
||
| private func mapMediaIdsToMedia(_ mediaIds: [Int]) -> [Media] { |
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.
Any Media objects returned from this method aren't thread-safe – it looks like a lot of what's going on here should happen on the main thread, but can we add assertions to ensure that is the case?
We could also convert these to thread-safe objects, but that might be overkill at this point?
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.
Thank you for noting this. I am quite unfamiliar with the subject of thread safety, so I appreciate that inquiries and suggestions.
I added an assertion in 1867499 based on what I understand of your feedback. Please let me know if I misunderstood or you have alternatives to suggest.
jkmassel
left a comment
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 tested this and it works well. I have a few code-level suggestions, but I don't think this needs additional review if/when they're addressed
The File block does not provide these value.
The returned `Media` entities are not thread-safe.


Related
Description
Enable attaching media selected from the Media Library.
To test: See wordpress-mobile/GutenbergKit#35.
Regression Notes
Existing Media Library support in Gutenberg Mobile, Aztec, etc.
Manually tested Media Library support in alternative editors.
Not a priority for this experimental editor.
PR submission checklist:
RELEASE-NOTES.txtif necessary.Testing checklist: