From 214a1e0722f20664e6fa855f939a79cafbba03bf Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 12 Apr 2024 09:40:31 -0700 Subject: [PATCH] Kotlinify DevSupportManager interface (#44056) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44056 ## Changelog: [Internal] - Was looking into how devsupport is exactly implemented on different platforms (in the context of doing it for a new platform) and figured I may just well convert this to Koltin in the process (helped to understand inner working details as well). Reviewed By: christophpurrer Differential Revision: D56058560 fbshipit-source-id: 1e2ffcec480c5fa3fd8b6494c29a0db6f94aec78 --- .../interfaces/DevSupportManager.java | 134 ------------------ .../interfaces/DevSupportManager.kt | 116 +++++++++++++++ 2 files changed, 116 insertions(+), 134 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.java deleted file mode 100644 index b293faa801f8fb..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.devsupport.interfaces; - -import android.app.Activity; -import android.util.Pair; -import android.view.View; -import androidx.annotation.Nullable; -import com.facebook.react.bridge.JSExceptionHandler; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.common.SurfaceDelegate; -import com.facebook.react.modules.debug.interfaces.DeveloperSettings; -import java.io.File; - -/** - * Interface for accessing and interacting with development features. In dev mode, use the - * implementation {@link BridgeDevSupportManager}. In production mode, use the dummy implementation - * {@link ReleaseDevSupportManager}. - */ -public interface DevSupportManager extends JSExceptionHandler { - - void showNewJavaError(String message, Throwable e); - - void addCustomDevOption(String optionName, DevOptionHandler optionHandler); - - @Nullable - View createRootView(String appKey); - - void destroyRootView(View rootView); - - void showNewJSError(String message, ReadableArray details, int errorCookie); - - void updateJSError(final String message, final ReadableArray details, final int errorCookie); - - void hideRedboxDialog(); - - void showDevOptionsDialog(); - - void setDevSupportEnabled(boolean isDevSupportEnabled); - - void startInspector(); - - void stopInspector(); - - boolean getDevSupportEnabled(); - - DeveloperSettings getDevSettings(); - - RedBoxHandler getRedBoxHandler(); - - void onNewReactContextCreated(ReactContext reactContext); - - void onReactInstanceDestroyed(ReactContext reactContext); - - String getSourceMapUrl(); - - String getSourceUrl(); - - String getJSBundleURLForRemoteDebugging(); - - String getDownloadedJSBundleFile(); - - boolean hasUpToDateJSBundleInCache(); - - void reloadSettings(); - - void handleReloadJS(); - - void reloadJSFromServer(final String bundleURL); - - void reloadJSFromServer(final String bundleURL, final BundleLoadCallback callback); - - void loadSplitBundleFromServer(String bundlePath, DevSplitBundleCallback callback); - - void isPackagerRunning(PackagerStatusCallback callback); - - void setHotModuleReplacementEnabled(final boolean isHotModuleReplacementEnabled); - - void setRemoteJSDebugEnabled(final boolean isRemoteJSDebugEnabled); - - void setFpsDebugEnabled(final boolean isFpsDebugEnabled); - - void toggleElementInspector(); - - @Nullable - File downloadBundleResourceFromUrlSync(final String resourceURL, final File outputFile); - - @Nullable - String getLastErrorTitle(); - - @Nullable - StackFrame[] getLastErrorStack(); - - @Nullable - ErrorType getLastErrorType(); - - int getLastErrorCookie(); - - void registerErrorCustomizer(ErrorCustomizer errorCustomizer); - - Pair processErrorCustomizers(Pair errorInfo); - - /** - * The PackagerLocationCustomizer allows you to have a dynamic packager location that is - * determined right before loading the packager. Your customizer must call |callback|, as loading - * will be blocked waiting for it to resolve. - */ - interface PackagerLocationCustomizer { - void run(Runnable callback); - } - - void setPackagerLocationCustomizer(PackagerLocationCustomizer packagerLocationCustomizer); - - @Nullable - Activity getCurrentActivity(); - - /** - * Create the surface delegate that the provided module should use to interact with - * - * @param moduleName the module name that helps decide which surface it should interact with - * @return a {@link SurfaceDelegate} instance - */ - @Nullable - SurfaceDelegate createSurfaceDelegate(String moduleName); - - /** Attempt to open the JS debugger on the host machine. */ - void openDebugger(); -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.kt new file mode 100644 index 00000000000000..9e6d3251ab5dae --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.kt @@ -0,0 +1,116 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.devsupport.interfaces + +import android.app.Activity +import android.util.Pair +import android.view.View +import com.facebook.react.bridge.JSExceptionHandler +import com.facebook.react.bridge.ReactContext +import com.facebook.react.bridge.ReadableArray +import com.facebook.react.common.SurfaceDelegate +import com.facebook.react.modules.debug.interfaces.DeveloperSettings +import java.io.File + +/** + * Interface for accessing and interacting with development features. In dev mode, use the + * implementation [BridgeDevSupportManager]. In production mode, use the dummy implementation + * [ReleaseDevSupportManager]. + */ +public interface DevSupportManager : JSExceptionHandler { + + public val devSettings: DeveloperSettings? + public val redBoxHandler: RedBoxHandler? + public val sourceMapUrl: String? + public val sourceUrl: String? + public val jSBundleURLForRemoteDebugging: String? + public val downloadedJSBundleFile: String? + public val lastErrorTitle: String? + public val lastErrorStack: Array? + public val lastErrorType: ErrorType? + public val lastErrorCookie: Int + public val currentActivity: Activity? + + public var devSupportEnabled: Boolean + + public fun showNewJavaError(message: String?, e: Throwable?) + + public fun addCustomDevOption(optionName: String?, optionHandler: DevOptionHandler?) + + public fun createRootView(appKey: String?): View? + + public fun destroyRootView(rootView: View?) + + public fun showNewJSError(message: String?, details: ReadableArray?, errorCookie: Int) + + public fun updateJSError(message: String?, details: ReadableArray?, errorCookie: Int) + + public fun hideRedboxDialog() + + public fun showDevOptionsDialog() + + public fun startInspector() + + public fun stopInspector() + + public fun onNewReactContextCreated(reactContext: ReactContext?) + + public fun onReactInstanceDestroyed(reactContext: ReactContext?) + + public fun hasUpToDateJSBundleInCache(): Boolean + + public fun reloadSettings() + + public fun handleReloadJS() + + public fun reloadJSFromServer(bundleURL: String) + + public fun reloadJSFromServer(bundleURL: String, callback: BundleLoadCallback) + + public fun loadSplitBundleFromServer(bundlePath: String, callback: DevSplitBundleCallback) + + public fun isPackagerRunning(callback: PackagerStatusCallback) + + public fun setHotModuleReplacementEnabled(isHotModuleReplacementEnabled: Boolean) + + public fun setRemoteJSDebugEnabled(isRemoteJSDebugEnabled: Boolean) + + public fun setFpsDebugEnabled(isFpsDebugEnabled: Boolean) + + public fun toggleElementInspector() + + public fun downloadBundleResourceFromUrlSync(resourceURL: String, outputFile: File?): File? + + public fun registerErrorCustomizer(errorCustomizer: ErrorCustomizer?) + + public fun processErrorCustomizers( + errorInfo: Pair>? + ): Pair>? + + public fun setPackagerLocationCustomizer(packagerLocationCustomizer: PackagerLocationCustomizer?) + + /** + * Create the surface delegate that the provided module should use to interact with + * + * @param moduleName the module name that helps decide which surface it should interact with + * @return a [SurfaceDelegate] instance + */ + public fun createSurfaceDelegate(moduleName: String?): SurfaceDelegate? + + /** Attempt to open the JS debugger on the host machine. */ + public fun openDebugger() + + /** + * The PackagerLocationCustomizer allows you to have a dynamic packager location that is + * determined right before loading the packager. Your customizer must call |callback|, as loading + * will be blocked waiting for it to resolve. + */ + public fun interface PackagerLocationCustomizer { + public fun run(callback: Runnable?) + } +}