From f9ded8c4e07b98989f317360556acd17f74ce487 Mon Sep 17 00:00:00 2001 From: Siobhan Date: Thu, 13 Apr 2023 00:00:40 +0100 Subject: [PATCH 1/2] feat: Set up listener for iOS save events --- packages/react-native-bridge/index.js | 6 ++++++ packages/react-native-bridge/ios/Gutenberg.swift | 4 ++++ .../ios/RNReactNativeGutenbergBridge.swift | 1 + test/native/setup.js | 1 + 4 files changed, 12 insertions(+) diff --git a/packages/react-native-bridge/index.js b/packages/react-native-bridge/index.js index d986f25055d0a6..27aed096aa15b6 100644 --- a/packages/react-native-bridge/index.js +++ b/packages/react-native-bridge/index.js @@ -69,6 +69,12 @@ export function subscribeFeaturedImageIdNativeUpdated( callback ) { ); } +export function subscribePostSaveEvent( callback ) { + return isIOS + ? gutenbergBridgeEvents.addListener( 'postHasBeenJustSaved', callback ) + : undefined; +} + /** * Request to subscribe to mediaUpload events * diff --git a/packages/react-native-bridge/ios/Gutenberg.swift b/packages/react-native-bridge/ios/Gutenberg.swift index 1ef54301d63379..ac6d77a1eecb29 100644 --- a/packages/react-native-bridge/ios/Gutenberg.swift +++ b/packages/react-native-bridge/ios/Gutenberg.swift @@ -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]) } diff --git a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift index b6fc433b47fef5..eccc765d30d99f 100644 --- a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift +++ b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift @@ -426,6 +426,7 @@ extension RNReactNativeGutenbergBridge { case toggleHTMLMode case updateHtml case featuredImageIdNativeUpdated + case postHasBeenJustSaved case mediaUpload case setFocusOnTitle case mediaAppend diff --git a/test/native/setup.js b/test/native/setup.js index 63bc0806e5bbf2..e9eeca07b2779f 100644 --- a/test/native/setup.js +++ b/test/native/setup.js @@ -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(), From a46f9845876524befbc4a9bfb93695a1ef2412b8 Mon Sep 17 00:00:00 2001 From: Siobhan Date: Mon, 17 Apr 2023 10:58:31 +0100 Subject: [PATCH 2/2] feat: Set up listener for Android save events --- .../RNReactNativeGutenbergBridgeModule.java | 5 +++++ .../wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java | 4 ++++ packages/react-native-bridge/index.js | 7 ++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java index 6388efb1f287eb..e779f15007ba31 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java @@ -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"; @@ -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); } diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java index 326d79f32b51bc..10e07b40ea6ee0 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java @@ -992,6 +992,10 @@ public void toggleEditorMode(boolean htmlModeEnabled) { mRnReactNativeGutenbergBridgePackage.getRNReactNativeGutenbergBridgeModule().toggleEditorMode(); } + public void sendToJSPostSaveEvent() { + mRnReactNativeGutenbergBridgePackage.getRNReactNativeGutenbergBridgeModule().sendToJSPostSaveEvent(); + } + public void appendMediaFiles(ArrayList mediaList) { if (isMediaSelectedCallbackRegistered() && mMediaPickedByUserOnBlock) { mMediaPickedByUserOnBlock = false; diff --git a/packages/react-native-bridge/index.js b/packages/react-native-bridge/index.js index 27aed096aa15b6..0129327903db13 100644 --- a/packages/react-native-bridge/index.js +++ b/packages/react-native-bridge/index.js @@ -70,9 +70,10 @@ export function subscribeFeaturedImageIdNativeUpdated( callback ) { } export function subscribePostSaveEvent( callback ) { - return isIOS - ? gutenbergBridgeEvents.addListener( 'postHasBeenJustSaved', callback ) - : undefined; + return gutenbergBridgeEvents.addListener( + 'postHasBeenJustSaved', + callback + ); } /**