Skip to content
This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Merged
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
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1.27.0
------
* Prefill caption for image blocks when available on the Media library
* New block: Buttons. From now you’ll be able to add the individual Button block only inside the Buttons block

1.26.0
Expand Down
4 changes: 2 additions & 2 deletions __device-tests__/gutenberg-editor-heading.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe( 'Gutenberg Editor tests', () => {
if ( isAndroid() ) {
await headingBlockElement.click();
}
await editorPage.sendTextToHeadingBlock( headingBlockElement, testData.heading );
await editorPage.sendTextToHeadingBlock( headingBlockElement, testData.heading, false );

await editorPage.addNewParagraphBlock();
let paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 2 );
Expand All @@ -60,7 +60,7 @@ describe( 'Gutenberg Editor tests', () => {

await editorPage.addNewHeadingBlock();
headingBlockElement = await editorPage.getHeadingBlockAtPosition( 4 );
await editorPage.sendTextToHeadingBlock( headingBlockElement, testData.heading );
await editorPage.sendTextToHeadingBlock( headingBlockElement, testData.heading, false );

await editorPage.addNewParagraphBlock();
paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 5 );
Expand Down
2 changes: 1 addition & 1 deletion __device-tests__/gutenberg-editor-image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe( 'Gutenberg Editor Image Block tests', () => {
imageBlock = await editorPage.getImageBlockAtPosition( 1 );
await imageBlock.click();
await swipeUp( driver, imageBlock );
await editorPage.enterCaptionToSelectedImageBlock( testData.imageCaption );
await editorPage.enterCaptionToSelectedImageBlock( testData.imageCaption, true );
await editorPage.dismissKeyboard();
imageBlock = await editorPage.getImageBlockAtPosition( 1 );
await imageBlock.click();
Expand Down
19 changes: 18 additions & 1 deletion __device-tests__/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,28 @@ const typeString = async ( driver: wd.PromiseChainWebdriver, element: wd.Promise

const typeStringIos = async ( driver: wd.PromiseChainWebdriver, element: wd.PromiseChainWebdriver.Element, str: string, clear: boolean ) => {
if ( clear ) {
await element.clear();
//await element.clear(); This was not working correctly on iOS so need a custom implementation
await clearTextBox( driver, element );
}
await element.type( str );
};

const clearTextBox = async ( driver: wd.PromiseChainWebdriver, element: wd.PromiseChainWebdriver.Element ) => {
await element.click();
let originalText = await element.text();
let text = originalText;
// We are double tapping on the text field and pressing backspace until all content is removed.
do {
originalText = await element.text();
const action = new wd.TouchAction( driver );
action.tap( { el: element, count: 2 } );
Comment thread
ceyhun marked this conversation as resolved.
Resolved
await action.perform();
await element.type( '\b' );
text = await element.text();
// We compare with the original content and not empty because text always return any hint set on the element.
} while ( originalText !== text );
};

const typeStringAndroid = async (
driver: wd.PromiseChainWebdriver,
element: wd.PromiseChainWebdriver.Element,
Expand Down
2 changes: 1 addition & 1 deletion __device-tests__/pages/editor-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export default class EditorPage {
}

async enterCaptionToSelectedImageBlock( caption: string, clear: boolean = true ) {
const imageBlockCaptionField = await this.driver.elementByXPath( '//XCUIElementTypeButton[@name="Image caption. Empty"]' );
const imageBlockCaptionField = await this.driver.elementByXPath( '//XCUIElementTypeButton[starts-with(@name, "Image caption.")]' );
await imageBlockCaptionField.click();
await typeString( this.driver, imageBlockCaptionField, caption, clear );
}
Expand Down
8 changes: 8 additions & 0 deletions android/app/src/main/java/com/gutenberg/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

public class MainApplication extends Application implements ReactApplication {

Expand Down Expand Up @@ -56,6 +57,13 @@ public void requestMediaPickFromDeviceLibrary(MediaUploadCallback mediaUploadCal

@Override
public void requestMediaPickFromMediaLibrary(MediaUploadCallback mediaUploadCallback, Boolean allowMultipleSelection, MediaType mediaType) {
List<RNMedia> rnMediaList = new ArrayList<>();
if (mediaType == MediaType.IMAGE) {
rnMediaList.add(new Media(1, "https://cldup.com/cXyG__fTLN.jpg", "image", "Mountain" ));
} else if (mediaType == MediaType.VIDEO) {
rnMediaList.add(new Media(2, "https://i.cloudup.com/YtZFJbuQCE.mov", "video", "Cloudup" ));
}
mediaUploadCallback.onUploadMediaFileSelected(rnMediaList);
}


Expand Down
65 changes: 65 additions & 0 deletions android/app/src/main/java/com/gutenberg/Media.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.gutenberg;

import androidx.annotation.NonNull;

import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.MediaType;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.RNMedia;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;

import java.util.Locale;

public class Media implements RNMedia {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wish we had the kotlin dependency setup to reduce this to 4 LoCs :)

@hypest hypest Apr 30, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Transformed the wish to a ticket 🤷‍♂️ #2203

private int mId;
private String mUrl;
private String mType;
private String mCaption;

public Media(int id, String url, String type, String caption) {
this.mId = id;
this.mUrl = url;
this.mType = type;
this.mCaption = caption;
}

public int getId() {
return mId;
}

public void setId(int id) {
this.mId = id;
}

public String getUrl() {
return mUrl;
}

public void setUrl(String url) {
this.mUrl = url;
}

public String getType() {
return mType;
}

public void setType(String mediaType) {
this.mType = mediaType;
}

public String getCaption() {
return mCaption;
}

public void setCaption(String caption) {
this.mCaption = caption;
}

public WritableMap toMap() {
WritableMap map = new WritableNativeMap();
map.putInt("id", mId);
map.putString("url", mUrl);
map.putString("type", mType);
map.putString("caption", mCaption);
return map;
}
}
6 changes: 3 additions & 3 deletions ios/gutenberg/GutenbergViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
case .image:
if(allowMultipleSelection) {
callback([MediaInfo(id: 1, url: "https://cldup.com/cXyG__fTLN.jpg", type: "image"),
MediaInfo(id: 3, url: "https://cldup.com/cXyG__fTLN.jpg", type: "image")])
MediaInfo(id: 3, url: "https://cldup.com/cXyG__fTLN.jpg", type: "image", caption: "Mountain")])
} else {
callback([MediaInfo(id: 1, url: "https://cldup.com/cXyG__fTLN.jpg", type: "image")])
callback([MediaInfo(id: 1, url: "https://cldup.com/cXyG__fTLN.jpg", type: "image", caption: "Mountain")])
}
case .video:
if(allowMultipleSelection) {
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")])
callback([MediaInfo(id: 2, url: "https://i.cloudup.com/YtZFJbuQCE.mov", type: "video", caption: "Cloudup")])
}
default:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface RNMedia {
String getUrl();
int getId();
String getType();
String getCaption();
WritableMap toMap();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ public class Media implements RNMedia {
private int mId;
private String mUrl;
private String mType;
private String mCaption;

public Media(int id, String url, String type) {
public Media(int id, String url, String type, String caption) {
this.mId = id;
this.mUrl = url;
this.mType = type;
this.mCaption = caption;
}

public Media(int id, String url) {
this.mId = id;
this.mUrl = url;
this.mType = "";
this.mCaption = "";
}

public static Media createRNMediaUsingMimeType(final int id, final String url, @NonNull final String mimeType) {
public static Media createRNMediaUsingMimeType(final int id, final String url, @NonNull final String mimeType, final String caption) {
String type;

if (mimeType.startsWith(MediaType.IMAGE.name().toLowerCase(Locale.ROOT))) {
Expand All @@ -37,7 +40,7 @@ public static Media createRNMediaUsingMimeType(final int id, final String url, @
type = MediaType.OTHER.name().toLowerCase(Locale.ROOT);
}

return new Media(id, url, type);
return new Media(id, url, type, caption);
}


Expand Down Expand Up @@ -65,11 +68,20 @@ public void setType(String mediaType) {
this.mType = mediaType;
}

public String getCaption() {
return mCaption;
}

public void setCaption(String caption) {
this.mCaption = caption;
}

public WritableMap toMap() {
WritableMap map = new WritableNativeMap();
map.putInt("id", mId);
map.putString("url", mUrl);
map.putString("type", mType);
map.putString("caption", mCaption);
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ public void appendUploadMediaFiles(ArrayList<Media> mediaList) {

for (Media mediaToAppend : mediaList.subList(1, mediaList.size())) {
sendOrDeferAppendMediaSignal(mediaToAppend.getId(), mediaToAppend.getUrl(),
mediaToAppend.getType());
mediaToAppend.getType(), mediaToAppend.getCaption());
}
} else {
rnMediaList.addAll(mediaList);
Expand All @@ -682,14 +682,14 @@ public void appendUploadMediaFiles(ArrayList<Media> mediaList) {
// This case is for media that is shared from the device
for (Media mediaToAppend : mediaList) {
sendOrDeferAppendMediaSignal(mediaToAppend.getId(), mediaToAppend.getUrl(),
mediaToAppend.getType());
mediaToAppend.getType(), mediaToAppend.getCaption());
}
}

mAppendsMultipleSelectedToSiblingBlocks = false;
}

private void sendOrDeferAppendMediaSignal(final int mediaId, final String mediaUri, final String mediaType) {
private void sendOrDeferAppendMediaSignal(final int mediaId, final String mediaUri, final String mediaType, final String caption) {
// if editor is mounted, let's append the media file
if (mIsEditorMounted) {
if (!TextUtils.isEmpty(mediaUri) && mediaId > 0) {
Expand All @@ -699,7 +699,7 @@ private void sendOrDeferAppendMediaSignal(final int mediaId, final String mediaU
} else {
// save the URL, we'll add it once Editor is mounted
synchronized (WPAndroidGlueCode.this) {
mMediaToAddAfterMounting.put(mediaId, new Media(mediaId, mediaUri, mediaType));
mMediaToAddAfterMounting.put(mediaId, new Media(mediaId, mediaUri, mediaType, caption));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ public struct MediaInfo {
public let id: Int32?
public let url: String?
public let type: String?
public let caption: String?

public init(id: Int32?, url: String?, type: String?) {
public init(id: Int32?, url: String?, type: String?, caption: String? = nil) {
self.id = id
self.url = url
self.type = type
self.caption = caption
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,22 @@ extension RNReactNativeGutenbergBridge {
}

extension RNReactNativeGutenbergBridge {
enum mediaDictKeys {
static let IDKey = "id"
static let URLKey = "url"
static let TypeKey = "type"
enum MediaKey {
static let id = "id"
static let url = "url"
static let type = "type"
static let caption = "caption"
}
}

extension MediaInfo {

func encodeForJS() -> [String: Any] {
return [
RNReactNativeGutenbergBridge.mediaDictKeys.IDKey: id as Any,
RNReactNativeGutenbergBridge.mediaDictKeys.URLKey: url as Any,
RNReactNativeGutenbergBridge.mediaDictKeys.TypeKey: type as Any
RNReactNativeGutenbergBridge.MediaKey.id: id as Any,
RNReactNativeGutenbergBridge.MediaKey.url: url as Any,
RNReactNativeGutenbergBridge.MediaKey.type: type as Any,
RNReactNativeGutenbergBridge.MediaKey.caption: caption as Any
]
}
}