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] Listen for post save events #49781

Merged
merged 4 commits into from
Apr 20, 2023
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
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