From be98945f079928ee637f8867365815d4573e8d0f Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Wed, 6 Dec 2023 15:52:40 -0500 Subject: [PATCH] Revert "feat: Add Hook to monitor network connectivity status (#56609)" This reverts commit ed1b2467b0cdbc1ac553d71fd6d16bd254da4c8b. --- .../GutenbergBridgeJS2Parent.java | 6 --- .../RNReactNativeGutenbergBridgeModule.java | 17 ------- .../WPAndroidGlue/DeferredEventEmitter.java | 9 ---- .../WPAndroidGlue/WPAndroidGlueCode.java | 17 ------- packages/react-native-bridge/index.js | 48 ------------------- .../react-native-bridge/ios/Gutenberg.swift | 5 -- .../ios/GutenbergBridgeDelegate.swift | 2 - .../ios/RNReactNativeGutenbergBridge.m | 1 - .../ios/RNReactNativeGutenbergBridge.swift | 6 --- .../java/com/gutenberg/MainApplication.java | 5 -- .../GutenbergViewController.swift | 4 -- 11 files changed, 120 deletions(-) diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java index c1dc4bab896b3a..c6e20b29db072e 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java @@ -60,10 +60,6 @@ interface BlockTypeImpressionsCallback { void onRequestBlockTypeImpressions(ReadableMap impressions); } - interface ConnectionStatusCallback { - void onRequestConnectionStatus(boolean isConnected); - } - // Ref: https://github.com/facebook/react-native/blob/HEAD/Libraries/polyfills/console.js#L376 enum LogLevel { TRACE(0), @@ -187,6 +183,4 @@ void gutenbergDidRequestUnsupportedBlockFallback(ReplaceUnsupportedBlockCallback void toggleUndoButton(boolean isDisabled); void toggleRedoButton(boolean isDisabled); - - void requestConnectionStatus(ConnectionStatusCallback connectionStatusCallback); } 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 0073db769d9cd5..d922d863cb3011 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 @@ -23,7 +23,6 @@ import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.modules.core.DeviceEventManagerModule; -import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.ConnectionStatusCallback; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.MediaType; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.OtherMediaOptionsReceivedCallback; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.FocalPointPickerTooltipShownCallback; @@ -86,8 +85,6 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu public static final String MAP_KEY_FEATURED_IMAGE_ID = "featuredImageId"; - public static final String MAP_KEY_IS_CONNECTED = "isConnected"; - private boolean mIsDarkMode; public RNReactNativeGutenbergBridgeModule(ReactApplicationContext reactContext, @@ -536,18 +533,4 @@ public void generateHapticFeedback() { } } } - - @ReactMethod - public void requestConnectionStatus(final Callback jsCallback) { - ConnectionStatusCallback connectionStatusCallback = requestConnectionStatusCallback(jsCallback); - mGutenbergBridgeJS2Parent.requestConnectionStatus(connectionStatusCallback); - } - - private ConnectionStatusCallback requestConnectionStatusCallback(final Callback jsCallback) { - return new GutenbergBridgeJS2Parent.ConnectionStatusCallback() { - @Override public void onRequestConnectionStatus(boolean isConnected) { - jsCallback.invoke(isConnected); - } - }; - } } diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java index fe83bc8a14b540..7dd4dbf3811feb 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java @@ -15,7 +15,6 @@ import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; -import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_IS_CONNECTED; import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID; import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_NEW_ID; import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL; @@ -45,8 +44,6 @@ public interface JSEventEmitter { private static final String EVENT_FEATURED_IMAGE_ID_NATIVE_UPDATED = "featuredImageIdNativeUpdated"; - private static final String EVENT_CONNECTION_STATUS_CHANGE = "connectionStatusChange"; - private static final String MAP_KEY_MEDIA_FILE_STATE = "state"; private static final String MAP_KEY_MEDIA_FILE_MEDIA_ACTION_PROGRESS = "progress"; private static final String MAP_KEY_MEDIA_FILE_MEDIA_SERVER_ID = "mediaServerId"; @@ -225,12 +222,6 @@ public void sendToJSFeaturedImageId(int mediaId) { queueActionToJS(EVENT_FEATURED_IMAGE_ID_NATIVE_UPDATED, writableMap); } - public void onConnectionStatusChange(boolean isConnected) { - WritableMap writableMap = new WritableNativeMap(); - writableMap.putBoolean(MAP_KEY_IS_CONNECTED, isConnected); - queueActionToJS(EVENT_CONNECTION_STATUS_CHANGE, writableMap); - } - @Override public void onReplaceMediaFilesEditedBlock(String mediaFiles, String blockId) { WritableMap writableMap = new WritableNativeMap(); writableMap.putString(MAP_KEY_REPLACE_BLOCK_HTML, mediaFiles); 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 c0916d1417a34f..69adb653211da2 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 @@ -112,7 +112,6 @@ public class WPAndroidGlueCode { private OnToggleUndoButtonListener mOnToggleUndoButtonListener; private OnToggleRedoButtonListener mOnToggleRedoButtonListener; - private OnConnectionStatusEventListener mOnConnectionStatusEventListener; private boolean mIsEditorMounted; private String mContentHtml = ""; @@ -260,10 +259,6 @@ public interface OnToggleRedoButtonListener { void onToggleRedoButton(boolean isDisabled); } - public interface OnConnectionStatusEventListener { - boolean onRequestConnectionStatus(); - } - public void mediaSelectionCancelled() { mAppendsMultipleSelectedToSiblingBlocks = false; } @@ -599,12 +594,6 @@ public void toggleUndoButton(boolean isDisabled) { public void toggleRedoButton(boolean isDisabled) { mOnToggleRedoButtonListener.onToggleRedoButton(isDisabled); } - - @Override - public void requestConnectionStatus(ConnectionStatusCallback connectionStatusCallback) { - boolean isConnected = mOnConnectionStatusEventListener.onRequestConnectionStatus(); - connectionStatusCallback.onRequestConnectionStatus(isConnected); - } }, mIsDarkMode); return Arrays.asList( @@ -699,7 +688,6 @@ public void attachToContainer(ViewGroup viewGroup, OnSendEventToHostListener onSendEventToHostListener, OnToggleUndoButtonListener onToggleUndoButtonListener, OnToggleRedoButtonListener onToggleRedoButtonListener, - OnConnectionStatusEventListener onConnectionStatusEventListener, boolean isDarkMode) { MutableContextWrapper contextWrapper = (MutableContextWrapper) mReactRootView.getContext(); contextWrapper.setBaseContext(viewGroup.getContext()); @@ -725,7 +713,6 @@ public void attachToContainer(ViewGroup viewGroup, mOnSendEventToHostListener = onSendEventToHostListener; mOnToggleUndoButtonListener = onToggleUndoButtonListener; mOnToggleRedoButtonListener = onToggleRedoButtonListener; - mOnConnectionStatusEventListener = onConnectionStatusEventListener; sAddCookiesInterceptor.setOnAuthHeaderRequestedListener(onAuthHeaderRequestedListener); @@ -1162,10 +1149,6 @@ public void sendToJSFeaturedImageId(int mediaId) { mDeferredEventEmitter.sendToJSFeaturedImageId(mediaId); } - public void connectionStatusChange(boolean isConnected) { - mDeferredEventEmitter.onConnectionStatusChange(isConnected); - } - public void replaceUnsupportedBlock(String content, String blockId) { if (mReplaceUnsupportedBlockCallback != null) { mReplaceUnsupportedBlockCallback.replaceUnsupportedBlock(content, blockId); diff --git a/packages/react-native-bridge/index.js b/packages/react-native-bridge/index.js index 8e9065cc568e56..89f9f029901f9a 100644 --- a/packages/react-native-bridge/index.js +++ b/packages/react-native-bridge/index.js @@ -3,11 +3,6 @@ */ import { NativeModules, NativeEventEmitter, Platform } from 'react-native'; -/** - * WordPress dependencies - */ -import { useEffect, useState } from '@wordpress/element'; - const { RNReactNativeGutenbergBridge } = NativeModules; const isIOS = Platform.OS === 'ios'; const isAndroid = Platform.OS === 'android'; @@ -190,49 +185,6 @@ export function subscribeOnRedoPressed( callback ) { return gutenbergBridgeEvents.addListener( 'onRedoPressed', callback ); } -export function useIsConnected() { - const [ isConnected, setIsConnected ] = useState( null ); - - useEffect( () => { - let isCurrent = true; - - RNReactNativeGutenbergBridge.requestConnectionStatus( - ( isBridgeConnected ) => { - if ( ! isCurrent ) { - return; - } - - setIsConnected( isBridgeConnected ); - } - ); - - return () => { - isCurrent = false; - }; - }, [] ); - - useEffect( () => { - const subscription = subscribeConnectionStatus( - ( { isConnected: isBridgeConnected } ) => { - setIsConnected( isBridgeConnected ); - } - ); - - return () => { - subscription.remove(); - }; - }, [] ); - - return { isConnected }; -} - -function subscribeConnectionStatus( callback ) { - return gutenbergBridgeEvents.addListener( - 'connectionStatusChange', - callback - ); -} - /** * Request media picker for the given media source. * diff --git a/packages/react-native-bridge/ios/Gutenberg.swift b/packages/react-native-bridge/ios/Gutenberg.swift index de0d1b513f00dc..4175c1e2343c32 100644 --- a/packages/react-native-bridge/ios/Gutenberg.swift +++ b/packages/react-native-bridge/ios/Gutenberg.swift @@ -210,11 +210,6 @@ public class Gutenberg: UIResponder { bridgeModule.sendEventIfNeeded(.onRedoPressed, body: nil) } - public func connectionStatusChange(isConnected: Bool) { - var data: [String: Any] = ["isConnected": isConnected] - bridgeModule.sendEventIfNeeded(.connectionStatusChange, body: data) - } - private func properties(from editorSettings: GutenbergEditorSettings?) -> [String : Any] { var settingsUpdates = [String : Any]() settingsUpdates["isFSETheme"] = editorSettings?.isFSETheme ?? false diff --git a/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift b/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift index 8890cd4de0f7ec..83d087bccab9d1 100644 --- a/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift +++ b/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift @@ -283,8 +283,6 @@ public protocol GutenbergBridgeDelegate: AnyObject { func gutenbergDidRequestToggleUndoButton(_ isDisabled: Bool) func gutenbergDidRequestToggleRedoButton(_ isDisabled: Bool) - - func gutenbergDidRequestConnectionStatus() -> Bool } // MARK: - Optional GutenbergBridgeDelegate methods diff --git a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.m b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.m index 3d68e51ebcacb5..d333f8c1722ad9 100644 --- a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.m +++ b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.m @@ -42,6 +42,5 @@ @interface RCT_EXTERN_MODULE(RNReactNativeGutenbergBridge, NSObject) RCT_EXTERN_METHOD(generateHapticFeedback) RCT_EXTERN_METHOD(toggleUndoButton:(BOOL)isDisabled) RCT_EXTERN_METHOD(toggleRedoButton:(BOOL)isDisabled) -RCT_EXTERN_METHOD(requestConnectionStatus:(RCTResponseSenderBlock)callback) @end diff --git a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift index ec763b2b8aaa2c..8cf4f685bd22c4 100644 --- a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift +++ b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift @@ -421,11 +421,6 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter { func toggleRedoButton(_ isDisabled: Bool) { self.delegate?.gutenbergDidRequestToggleRedoButton(isDisabled) } - - @objc - func requestConnectionStatus(_ callback: @escaping RCTResponseSenderBlock) { - callback([self.delegate?.gutenbergDidRequestConnectionStatus() ?? true]) - } } // MARK: - RCTBridgeModule delegate @@ -455,7 +450,6 @@ extension RNReactNativeGutenbergBridge { case showEditorHelp case onUndoPressed case onRedoPressed - case connectionStatusChange } public override func supportedEvents() -> [String]! { diff --git a/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java b/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java index 4477f1cc1d9f35..d718b34f25db3b 100644 --- a/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java +++ b/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java @@ -308,11 +308,6 @@ public void toggleRedoButton(boolean isDisabled) { mainActivity.updateRedoItem(isDisabled); } } - - @Override - public void requestConnectionStatus(ConnectionStatusCallback connectionStatusCallback) { - connectionStatusCallback.onRequestConnectionStatus(true); - } }, isDarkMode()); return new DefaultReactNativeHost(this) { diff --git a/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift b/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift index ef95c7e65862f6..b269d1feb8ddfe 100644 --- a/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift +++ b/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift @@ -345,10 +345,6 @@ extension GutenbergViewController: GutenbergBridgeDelegate { } } } - - func gutenbergDidRequestConnectionStatus() -> Bool { - return true - } } extension GutenbergViewController: GutenbergWebDelegate {