Skip to content

Commit

Permalink
[RNMobile] Listen for post save events (#49781)
Browse files Browse the repository at this point in the history
The changes in this PR introduce a way for Gutenberg Mobile to detect post save events that are emitted from the native apps.
  • Loading branch information
Siobhan Bamber authored Apr 20, 2023
1 parent b0d6280 commit 73e6403
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu
private static final String EVENT_NAME_FOCUS_TITLE = "setFocusOnTitle";
private static final String EVENT_NAME_MEDIA_APPEND = "mediaAppend";
private static final String EVENT_NAME_TOGGLE_HTML_MODE = "toggleHTMLMode";
private static final String EVENT_NAME_POST_SAVE_EVENT = "postHasBeenJustSaved";
private static final String EVENT_NAME_NOTIFY_MODAL_CLOSED = "notifyModalClosed";
private static final String EVENT_NAME_PREFERRED_COLOR_SCHEME = "preferredColorScheme";
private static final String EVENT_NAME_MEDIA_REPLACE_BLOCK = "replaceBlock";
Expand Down Expand Up @@ -449,6 +450,10 @@ public void toggleEditorMode() {
emitToJS(EVENT_NAME_TOGGLE_HTML_MODE, null);
}

public void sendToJSPostSaveEvent() {
emitToJS(EVENT_NAME_POST_SAVE_EVENT, null);
}

public void notifyModalClosed() {
emitToJS(EVENT_NAME_NOTIFY_MODAL_CLOSED, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,10 @@ public void toggleEditorMode(boolean htmlModeEnabled) {
mRnReactNativeGutenbergBridgePackage.getRNReactNativeGutenbergBridgeModule().toggleEditorMode();
}

public void sendToJSPostSaveEvent() {
mRnReactNativeGutenbergBridgePackage.getRNReactNativeGutenbergBridgeModule().sendToJSPostSaveEvent();
}

public void appendMediaFiles(ArrayList<Media> mediaList) {
if (isMediaSelectedCallbackRegistered() && mMediaPickedByUserOnBlock) {
mMediaPickedByUserOnBlock = false;
Expand Down
7 changes: 7 additions & 0 deletions packages/react-native-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export function subscribeFeaturedImageIdNativeUpdated( callback ) {
);
}

export function subscribePostSaveEvent( callback ) {
return gutenbergBridgeEvents.addListener(
'postHasBeenJustSaved',
callback
);
}

/**
* Request to subscribe to mediaUpload events
*
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native-bridge/ios/Gutenberg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public class Gutenberg: UIResponder {
sendEvent(.featuredImageIdNativeUpdated, body: ["featuredImageId": mediaId])
}

public func postHasBeenJustSaved() {
sendEvent(.postHasBeenJustSaved)
}

public func replace(block: Block) {
sendEvent(.replaceBlock, body: ["html": block.content, "clientId": block.id])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ extension RNReactNativeGutenbergBridge {
case toggleHTMLMode
case updateHtml
case featuredImageIdNativeUpdated
case postHasBeenJustSaved
case mediaUpload
case setFocusOnTitle
case mediaAppend
Expand Down
1 change: 1 addition & 0 deletions test/native/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jest.mock( '@wordpress/react-native-bridge', () => {
subscribeSetFocusOnTitle: jest.fn(),
subscribeUpdateHtml: jest.fn(),
subscribeFeaturedImageIdNativeUpdated: jest.fn(),
subscribePostSaveEvent: jest.fn(),
subscribeMediaAppend: jest.fn(),
subscribeAndroidModalClosed: jest.fn(),
subscribeUpdateEditorSettings: jest.fn(),
Expand Down

1 comment on commit 73e6403

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 73e6403.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4756585860
📝 Reported issues:

Please sign in to comment.