Skip to content
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

[RNMobile] Add metadata property to MediaInfo #48994

Merged
merged 3 commits into from
Mar 21, 2023

Conversation

fluiddot
Copy link
Contributor

@fluiddot fluiddot commented Mar 10, 2023

What?

Add metadata property to MediaInfo class.

Why?

This new parameter will allow the editor's host to pass extra parameters of media items to blocks.

How?

Added the parameter on native files of the editor. The new parameter shouldn't impact the apps as a default value is defined.

Testing Instructions

  1. Build and open the demo app.
  2. Connect the demo app with the local Metro server.
  3. Apply the following patch file:
diff --git forkSrcPrefix/packages/block-library/src/video/edit.native.js forkDstPrefix/packages/block-library/src/video/edit.native.js
index 99225ba5d5c569d19a158f5b1a203c68aa353c33..194c116ae81ad01c7430fc5a3dbd3bb9878f490b 100644
--- forkSrcPrefix/packages/block-library/src/video/edit.native.js
+++ forkDstPrefix/packages/block-library/src/video/edit.native.js
@@ -154,9 +154,10 @@ class VideoEdit extends Component {
 		this.setState( { isUploadInProgress: false } );
 	}
 
-	onSelectMediaUploadOption( { id, url } ) {
+	onSelectMediaUploadOption( { id, url, metadata } ) {
 		const { setAttributes } = this.props;
 		setAttributes( { id, src: url } );
+		console.log( { metadata } );
 	}
 
 	onSelectURL( url ) {
  1. Add a Video block.
  2. Select "WordPress Media Library" option.
  3. Check the logs and observe that the metadata object was printed with the following data: {"metadata": {"extraID": "AbCdE"}}.

Testing Instructions for Keyboard

N/A

Screenshots or screencast

N/A

@fluiddot fluiddot added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label Mar 10, 2023
@fluiddot fluiddot self-assigned this Mar 10, 2023
@fluiddot fluiddot force-pushed the rnmobile/add-media-info-metadata branch 2 times, most recently from 75d9a7e to 788daa0 Compare March 14, 2023 17:55
): Media {
val type = convertToType(mimeType)
return Media(id, url, type, caption ?: "", title ?: "")
return Media(id, url, type, caption ?: "", title ?: "", alt ?: "", metadata)
Copy link
Contributor Author

@fluiddot fluiddot Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can replace this function because it was only used in the demo app and it has been updated in this PR. The function above is the one used in the Android app but remains unmodified.

case id, url, type, title, caption, alt, metadata
}

public init(id: Int32?, url: String?, type: String?, caption: String? = nil, title: String? = nil, alt: String? = nil, metadata: Encodable? = nil) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change shouldn't impact the iOS app as we set a default value for the new parameter metadata.

@@ -15,7 +15,8 @@ data class Media(
override val type: String,
override val caption: String = "",
override val title: String = "",
override val alt: String = ""
override val alt: String = "",
override val metadata: WritableMap = WritableNativeMap()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change shouldn't impact the Android app as we set a default value for the new parameter metadata.

@fluiddot fluiddot marked this pull request as ready for review March 14, 2023 18:09
@fluiddot fluiddot added the Mobile App - Automation Label used to initiate Mobile App PR Automation label Mar 14, 2023
@fluiddot fluiddot force-pushed the rnmobile/add-media-info-metadata branch from 788daa0 to bcf173d Compare March 15, 2023 10:55
Comment on lines +95 to +96
WritableNativeMap metadata = new WritableNativeMap();
metadata.putString("extraID", "AbCdE");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This metadata is used for testing purposes only.

@@ -97,7 +97,8 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
callback([MediaInfo(id: 2, url: "https://i.cloudup.com/YtZFJbuQCE.mov", type: "video"),
MediaInfo(id: 4, url: "https://i.cloudup.com/YtZFJbuQCE.mov", type: "video")])
} else {
callback([MediaInfo(id: 2, url: "https://i.cloudup.com/YtZFJbuQCE.mov", type: "video", caption: "Cloudup")])
let metadata = ["extraID": "AbCdE"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This metadata is used for testing purposes only.

Copy link
Contributor

@SiobhyB SiobhyB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! :) I confirmed that the logging worked as expected following the testing steps.

Screenshot 2023-03-16 at 12 33 48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - Automation Label used to initiate Mobile App PR Automation Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants