Skip to content

Commit

Permalink
[RNMobile] Unsupported block fallback send block title and name (#23450)
Browse files Browse the repository at this point in the history
* Unsupported block fallback: Sending both block title and block name to native

* Lint fixes

* [iOS]: Adding documentation to Block struct
  • Loading branch information
etoledom authored Jun 30, 2020
1 parent 3e5af66 commit de041fd
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 20 deletions.
9 changes: 5 additions & 4 deletions packages/block-library/src/missing/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class UnsupportedBlockEdit extends Component {
this.setState( { sendFallbackMessage: true } );
}

renderSheet( title ) {
renderSheet( blockTitle, blockName ) {
const { getStylesFromColorScheme, attributes, clientId } = this.props;
const infoTextStyle = getStylesFromColorScheme(
styles.infoText,
Expand All @@ -95,7 +95,7 @@ export class UnsupportedBlockEdit extends Component {
__( "'%s' isn't yet supported on WordPress for Android" )
: // translators: %s: Name of the block
__( "'%s' isn't yet supported on WordPress for iOS" );
const infoTitle = sprintf( titleFormat, title );
const infoTitle = sprintf( titleFormat, blockTitle );

const actionButtonStyle = getStylesFromColorScheme(
styles.actionButton,
Expand All @@ -115,7 +115,8 @@ export class UnsupportedBlockEdit extends Component {
requestUnsupportedBlockFallback(
attributes.originalContent,
clientId,
title
blockName,
blockTitle
);
}, 100 );
this.setState( { sendFallbackMessage: false } );
Expand Down Expand Up @@ -209,7 +210,7 @@ export class UnsupportedBlockEdit extends Component {
/>
<Text style={ titleStyle }>{ title }</Text>
{ subtitle }
{ this.renderSheet( title ) }
{ this.renderSheet( title, originalName ) }
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public static GutenbergUserEvent getEnum(String eventName) {
void gutenbergDidRequestUnsupportedBlockFallback(ReplaceUnsupportedBlockCallback replaceUnsupportedBlockCallback,
String content,
String blockId,
String blockName);
String blockName,
String blockTitle);

void onAddMention(Consumer<String> onSuccess);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ public void logUserEvent(String eventName, ReadableMap eventProperties) {
}

@ReactMethod
public void requestUnsupportedBlockFallback(String content, String blockId, String blockName) {
public void requestUnsupportedBlockFallback(String content, String blockId, String blockName, String blockTitle) {
mGutenbergBridgeJS2Parent.gutenbergDidRequestUnsupportedBlockFallback((savedContent, savedBlockId) ->
replaceBlock(savedContent, savedBlockId), content, blockId, blockName);
replaceBlock(savedContent, savedBlockId), content, blockId, blockName, blockTitle);
}

private void replaceBlock(String content, String blockId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ public class UnsupportedBlock {

private String mId;
private String mName;
private String mTitle;
private String mContent;

public UnsupportedBlock(String id, String name, String content) {
public UnsupportedBlock(String id, String name, String title, String content) {
mId = id;
mName = name;
mTitle = title;
mContent = content;
}

Expand All @@ -20,6 +22,10 @@ public String getName() {
return mName;
}

public String getTitle() {
return mTitle;
}

public String getContent() {
return mContent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,11 @@ public void logUserEvent(GutenbergUserEvent event, ReadableMap eventProperties)
public void gutenbergDidRequestUnsupportedBlockFallback(ReplaceUnsupportedBlockCallback replaceUnsupportedBlockCallback,
String content,
String blockId,
String blockName) {
String blockName,
String blockTitle) {
mReplaceUnsupportedBlockCallback = replaceUnsupportedBlockCallback;
mOnGutenbergDidRequestUnsupportedBlockFallbackListener.
gutenbergDidRequestUnsupportedBlockFallback(new UnsupportedBlock(blockId, blockName, content));
gutenbergDidRequestUnsupportedBlockFallback(new UnsupportedBlock(blockId, blockName, blockTitle, content));
}

@Override
Expand Down
9 changes: 6 additions & 3 deletions packages/react-native-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,20 @@ export function requestMediaPicker( source, filter, multiple, callback ) {
*
* @param {string} htmlContent Raw html content of the block.
* @param {string} blockClientId the clientId of the block.
* @param {string} blockName the user-facing, localized block name.
* @param {string} blockName the internal system block name.
* @param {string} blockTitle the user-facing, localized block name.
*/
export function requestUnsupportedBlockFallback(
htmlContent,
blockClientId,
blockName
blockName,
blockTitle
) {
RNReactNativeGutenbergBridge.requestUnsupportedBlockFallback(
htmlContent,
blockClientId,
blockName
blockName,
blockTitle
);
}

Expand Down
11 changes: 10 additions & 1 deletion packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ public struct MediaInfo {
}
}

/// Wrapper for single block data
public struct Block {
/// Gutenberg internal block ID
public let id: String
/// Gutenberg internal block name
public let name: String
/// User facing block name string (localized)
public let title: String
/// Block HTML content
public let content: String

/// Creates a copy of the receiver modifying only its content field.
/// - Parameter newContent: The content for the new block instance.
/// - Returns: A new block instance with copied fields and new content.
public func replacingContent(with newContent: String) -> Block {
Block(id: id, name: name, content: newContent)
Block(id: id, name: name, title: title, content: newContent)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ open class GutenbergWebSingleBlockViewController: UIViewController {
navigationItem.rightBarButtonItem = saveButton
navigationItem.leftBarButtonItem = cancelButton
let localizedTitle = NSLocalizedString("Edit %@ block", comment: "Title of Gutenberg WEB editor running on a Web View. %@ is the localized block name.")
title = String(format: localizedTitle, block.name)
title = String(format: localizedTitle, block.title)
}

func addCoverView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ @interface RCT_EXTERN_MODULE(RNReactNativeGutenbergBridge, NSObject)
RCT_EXTERN_METHOD(requestImageFullscreenPreview:(NSString *)currentImageUrlString originalImageUrlString:(NSString *)originalImageUrlString)
RCT_EXTERN_METHOD(requestMediaEditor:(NSString *)mediaUrl callback:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(logUserEvent:(NSString *)event properties:(NSDictionary *)properties)
RCT_EXTERN_METHOD(requestUnsupportedBlockFallback:(NSString *)content blockId:(NSString *)blockId blockName:(NSString *)blockName)
RCT_EXTERN_METHOD(requestUnsupportedBlockFallback:(NSString *)content blockId:(NSString *)blockId blockName:(NSString *)blockName blockTitle:(NSString *)blockTitle)
RCT_EXTERN_METHOD(addMention:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)rejecter)
RCT_EXTERN_METHOD(requestStarterPageTemplatesTooltipShown:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(setStarterPageTemplatesTooltipShown:(BOOL)tooltipShown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter {
}

@objc
func requestUnsupportedBlockFallback(_ content: String, blockId: String, blockName: String) {
func requestUnsupportedBlockFallback(_ content: String, blockId: String, blockName: String, blockTitle: String) {
DispatchQueue.main.async {
let block = Block(id: blockId, name: blockName, content: content)
let block = Block(id: blockId, name: blockName, title: blockTitle, content: content)
self.delegate?.gutenbergDidRequestUnsupportedBlockFallback(for: block)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ public void performRequest(String path, Consumer<String> onSuccess, Consumer<Bun
public void gutenbergDidRequestUnsupportedBlockFallback(ReplaceUnsupportedBlockCallback replaceUnsupportedBlockCallback,
String content,
String blockId,
String blockName) {
String blockName,
String blockTitle) {
mReplaceUnsupportedBlockCallback = replaceUnsupportedBlockCallback;
openGutenbergWebView(content, blockId, blockName);
openGutenbergWebView(content, blockId, blockTitle);
}

@Override
Expand Down

0 comments on commit de041fd

Please sign in to comment.