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 media caption when adding an image or video #28469

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/block-library/src/video/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ class VideoEdit extends Component {
this.setState( { isUploadInProgress: false } );
}

onSelectMediaUploadOption( { id, url } ) {
onSelectMediaUploadOption( { id, url, caption } ) {
const { setAttributes } = this.props;
setAttributes( { id, src: url } );
setAttributes( { id, src: url, caption } );
}

onVideoContanerLayout( event ) {
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/provider/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class NativeEditorProvider extends Component {
[ payload.mediaType === 'image'
? 'url'
: 'src' ]: payload.mediaUrl,
caption: payload.mediaCaption,
} );

const indexAfterSelected = this.props.selectedBlockIndex + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu
public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID = "mediaId";
public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL = "mediaUrl";
public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_TYPE = "mediaType";
public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_CAPTION = "mediaCaption";
private static final String MAP_KEY_THEME_UPDATE_COLORS = "colors";
private static final String MAP_KEY_THEME_UPDATE_GRADIENTS = "gradients";
public static final String MAP_KEY_MEDIA_FINAL_SAVE_RESULT_SUCCESS_VALUE = "success";
Expand Down Expand Up @@ -122,11 +123,12 @@ public void showNoticeInJS(String message) {
emitToJS(EVENT_NAME_SHOW_NOTICE, writableMap);
}

public void appendNewMediaBlock(int mediaId, String mediaUri, String mediaType) {
public void appendNewMediaBlock(int mediaId, String mediaUri, String mediaType, String mediaCaption) {
WritableMap writableMap = new WritableNativeMap();
writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_TYPE, mediaType);
writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL, mediaUri);
writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID, mediaId);
writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_CAPTION, mediaCaption);
emitToJS(EVENT_NAME_MEDIA_APPEND, writableMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,9 @@ public void setFocusOnTitle() {
mRnReactNativeGutenbergBridgePackage.getRNReactNativeGutenbergBridgeModule().setFocusOnTitleInJS();
}

public void appendNewMediaBlock(int mediaId, String mediaUri, String mediaType) {
public void appendNewMediaBlock(int mediaId, String mediaUri, String mediaType, String mediaCaption) {
mRnReactNativeGutenbergBridgePackage.getRNReactNativeGutenbergBridgeModule()
.appendNewMediaBlock(mediaId, mediaUri, mediaType);
.appendNewMediaBlock(mediaId, mediaUri, mediaType, mediaCaption);
}

public void setPreferredColorScheme(boolean isDarkMode) {
Expand Down Expand Up @@ -864,7 +864,7 @@ private void sendOrDeferAppendMediaSignal(Media media) {
if (mIsEditorMounted) {
if (!TextUtils.isEmpty(media.getUrl()) && media.getId() > 0) {
// send signal to JS
appendNewMediaBlock(media.getId(), media.getUrl(), media.getType());
appendNewMediaBlock(media.getId(), media.getUrl(), media.getType(), media.getCaption());
}
} else {
// save the URL, we'll add it once Editor is mounted
Expand All @@ -882,7 +882,7 @@ private synchronized void dispatchOneMediaToAddAtATimeIfAvailable() {
Media media = entry.getValue();
if (!TextUtils.isEmpty(media.getUrl()) && mediaId > 0) {
// send signal to JS
appendNewMediaBlock(mediaId, media.getUrl(), media.getType());
appendNewMediaBlock(mediaId, media.getUrl(), media.getType(), media.getCaption());
iter.remove();
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native-bridge/ios/Gutenberg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ public class Gutenberg: NSObject {
sendEvent(event, body: data)
}

public func appendMedia(id: Int32, url: URL, type: MediaType) {
public func appendMedia(id: Int32, url: URL, type: MediaType, caption: String? = nil) {
let data: [String: Any] = [
"mediaId" : id,
"mediaUrl" : url.absoluteString,
"mediaType": type.rawValue,
"mediaCaption": caption,
]
sendEvent(.mediaAppend, body: data)
}
Expand Down