Skip to content

Commit

Permalink
Kotlinify the remaining interfaces in react.bridge (facebook#44546)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#44546

# Changelog:
[Internal] -

This wraps up moving all of the interfaces to Kotling inside `react.bridge`.

Differential Revision: D57253634
  • Loading branch information
rshest authored and facebook-github-bot committed May 12, 2024
1 parent 3d5aa15 commit c332165
Show file tree
Hide file tree
Showing 21 changed files with 367 additions and 404 deletions.
7 changes: 6 additions & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ public abstract interface class com/facebook/react/bridge/JavaJSExecutor$Factory
public abstract fun create ()Lcom/facebook/react/bridge/JavaJSExecutor;
}

public class com/facebook/react/bridge/JavaJSExecutor$ProxyExecutorException : java/lang/Exception {
public final class com/facebook/react/bridge/JavaJSExecutor$ProxyExecutorException : java/lang/Exception {
public fun <init> (Ljava/lang/Throwable;)V
}

Expand Down Expand Up @@ -1004,6 +1004,11 @@ public abstract interface class com/facebook/react/bridge/OnBatchCompleteListene
public abstract fun onBatchComplete ()V
}

public abstract interface class com/facebook/react/bridge/PerformanceCounter {
public abstract fun getPerformanceCounters ()Ljava/util/Map;
public abstract fun profileNextBatch ()V
}

public abstract interface class com/facebook/react/bridge/Promise {
public abstract fun reject (Ljava/lang/String;)V
public abstract fun reject (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.bridge

import android.app.Activity
import android.content.Intent

/**
* Listener for receiving activity events. Consider using [BaseActivityEventListener] if you're not
* interested in all the events sent to this interface.
*/
public interface ActivityEventListener {
/** Called when host (activity/service) receives an [Activity.onActivityResult] call. */
public fun onActivityResult(activity: Activity?, requestCode: Int, resultCode: Int, data: Intent?)

/** Called when a new intent is passed to the activity */
public fun onNewIntent(intent: Intent?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.bridge;

package com.facebook.react.bridge
/**
* Interface that represent javascript callback function which can be passed to the native module as
* a method parameter.
*/
public interface Callback {

/**
* Schedule javascript function execution represented by this {@link Callback} instance
* Schedule javascript function execution represented by this [Callback] instance
*
* @param args arguments passed to javascript callback method via bridge
*/
void invoke(Object... args);
public operator fun invoke(vararg args: Any?)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.bridge

import android.content.res.AssetManager

/** An interface for classes that initialize JavaScript using [JSBundleLoader] */
public interface JSBundleLoaderDelegate {
/**
* Load a JS bundle from Android assets. See [JSBundleLoader.createAssetLoader]
*
* @param assetManager
* @param assetURL
* @param loadSynchronously
*/
public fun loadScriptFromAssets(
assetManager: AssetManager,
assetURL: String,
loadSynchronously: Boolean
)

/**
* Load a JS bundle from the filesystem. See [JSBundleLoader.createFileLoader] and
* [JSBundleLoader.createCachedBundleFromNetworkLoader]
*
* @param fileName
* @param sourceURL
* @param loadSynchronously
*/
public fun loadScriptFromFile(fileName: String, sourceURL: String, loadSynchronously: Boolean)

/**
* Load a split JS bundle from the filesystem. See
* [ ][JSBundleLoader.createCachedSplitBundleFromNetworkLoader].
*/
public fun loadSplitBundleFromFile(fileName: String, sourceURL: String)

/**
* This API is used in situations where the JS bundle is being executed not on the device, but on
* a host machine. In that case, we must provide two source URLs for the JS bundle: One to be used
* on the device, and one to be used on the remote debugging machine.
*
* @param deviceURL A source URL that is accessible from this device.
* @param remoteURL A source URL that is accessible from the remote machine executing the JS.
*/
public fun setSourceURLs(deviceURL: String, remoteURL: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.bridge;
package com.facebook.react.bridge

/**
* Interface for a class that knows how to handle an Exception invoked from JS. Since these
* Exceptions are triggered by JS calls (and can be fixed in JS), a common way to handle one is to
* show a error dialog and allow the developer to change and reload JS.
*
* <p>We should also note that we have a unique stance on what 'caused' means: even if there's a bug
* in the framework/native code, it was triggered by JS and theoretically since we were able to set
* up the React Instance, JS could change its logic, reload, and not trigger that crash.
* We should also note that we have a unique stance on what 'caused' means: even if there's a bug in
* the framework/native code, it was triggered by JS and theoretically since we were able to set up
* the React Instance, JS could change its logic, reload, and not trigger that crash.
*/
public interface JSExceptionHandler {

/** Do something to display or log the exception. */
void handleException(Exception e);
public fun handleException(e: Exception)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,35 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.bridge;
package com.facebook.react.bridge

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.proguard.annotations.DoNotStrip

/**
* This is class represents java version of native js executor interface. When set through {@link
* ProxyJavaScriptExecutor} as a {@link CatalystInstance} executor, native code will delegate js
* calls to the given implementation of this interface.
* This is class represents java version of native js executor interface. When set through [ ] as a
* [CatalystInstance] executor, native code will delegate js calls to the given implementation of
* this interface.
*/
@DoNotStrip
public interface JavaJSExecutor {
interface Factory {
JavaJSExecutor create() throws Exception;
public interface Factory {
@Throws(Exception::class) public fun create(): JavaJSExecutor?
}

class ProxyExecutorException extends Exception {
public ProxyExecutorException(Throwable cause) {
super(cause);
}
}
public class ProxyExecutorException(cause: Throwable) : Exception(cause)

/**
* Close this executor and cleanup any resources that it was using. No further calls are expected
* after this.
*/
void close();
public fun close()

/**
* Load javascript into the js context
*
* @param sourceURL url or file location from which script content was loaded
*/
@DoNotStrip
void loadBundle(String sourceURL) throws ProxyExecutorException;
@DoNotStrip @Throws(ProxyExecutorException::class) public fun loadBundle(sourceURL: String)

/**
* Execute javascript method within js context
Expand All @@ -48,8 +43,8 @@ public ProxyExecutorException(Throwable cause) {
* @return json encoded value returned from the method call
*/
@DoNotStrip
String executeJSCall(String methodName, String jsonArgsArray) throws ProxyExecutorException;
@Throws(ProxyExecutorException::class)
public fun executeJSCall(methodName: String, jsonArgsArray: String?): String?

@DoNotStrip
void setGlobalVariable(String propertyName, String jsonEncodedValue);
@DoNotStrip public fun setGlobalVariable(propertyName: String, jsonEncodedValue: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.bridge;
package com.facebook.react.bridge

public interface JavaScriptExecutorFactory {
JavaScriptExecutor create() throws Exception;
@Throws(Exception::class) public fun create(): JavaScriptExecutor

/**
* Starts the sampling profiler for this specific JavaScriptExecutor Sampling profiler is usually
* a singleton on the runtime, hence the method exists here and not in {@link JavaScriptExecutor}
* a singleton on the runtime, hence the method exists here and not in [JavaScriptExecutor]
*/
void startSamplingProfiler();
public fun startSamplingProfiler()

/**
* Stops the Sampling profile
*
* @param filename The filename where the results of the sampling profiler are dumped to
*/
void stopSamplingProfiler(String filename);
public fun stopSamplingProfiler(filename: String)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.bridge

import com.facebook.proguard.annotations.DoNotStrip

/**
* Interface denoting that a class is the interface to a module with the same name in JS. Calling
* functions on this interface will result in corresponding methods in JS being called.
*
* When extending JavaScriptModule and registering it with a CatalystInstance, all public methods
* are assumed to be implemented on a JS module with the same name as this class. Calling methods on
* the object returned from [ReactContext.getJSModule] or [CatalystInstance.getJSModule] will result
* in the methods with those names exported by that module being called in JS.
*
* NB: JavaScriptModule does not allow method name overloading because JS does not allow method name
* overloading.
*/
@DoNotStrip public interface JavaScriptModule
Loading

0 comments on commit c332165

Please sign in to comment.