Skip to content

Commit

Permalink
introduce CallInvokerHolder stable API (#44381)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #44381

Changelog: [Android][Added]

I am adding this API in favor of RCTRuntimeExecutor. CallInvoker is now preferred because after #43375, the CallInvoker has access to the jsi::Runtime. Since the community is using CallInvoker already for their async access use cases, CallInvoker is the preferred choice of RuntimeExecutor / RuntimeScheduler because of easier migration. Also, having a wrapper like CallInvoker will give us more flexibility in the future if we want to expand this API.

this will be forward compatible in the old architecture

Reviewed By: RSNara

Differential Revision: D56866817

fbshipit-source-id: 4096847c52559d9a49feb072a0385da6b64392d4
  • Loading branch information
philIip authored and facebook-github-bot committed May 4, 2024
1 parent 377c2f5 commit 69bb4fc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ public abstract class com/facebook/react/bridge/ReactContext : android/content/C
public fun getCurrentActivity ()Landroid/app/Activity;
public fun getExceptionHandler ()Lcom/facebook/react/bridge/JSExceptionHandler;
public fun getFabricUIManager ()Lcom/facebook/react/bridge/UIManager;
public fun getJSCallInvokerHolder ()Lcom/facebook/react/turbomodule/core/interfaces/CallInvokerHolder;
public fun getJSExceptionHandler ()Lcom/facebook/react/bridge/JSExceptionHandler;
public fun getJSMessageQueueThread ()Lcom/facebook/react/bridge/queue/MessageQueueThread;
public fun getJSModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/JavaScriptModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public interface CatalystInstance
* Returns a hybrid object that contains a pointer to a JS CallInvoker, which is used to schedule
* work on the JS Thread. Required for TurboModuleManager initialization.
*/
@Deprecated
CallInvokerHolder getJSCallInvokerHolder();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.facebook.react.common.LifecycleState;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.annotations.DeprecatedInNewArchitecture;
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.concurrent.CopyOnWriteArraySet;
Expand Down Expand Up @@ -581,6 +582,17 @@ public boolean isBridgeless() {
return null;
}

/**
* Returns a hybrid object that contains a pointer to a JS CallInvoker, which is used to schedule
* work on the JS Thread.
*/
public @Nullable CallInvokerHolder getJSCallInvokerHolder() {
if (mCatalystInstance != null) {
return mCatalystInstance.getJSCallInvokerHolder();
}
return null;
}

@DeprecatedInNewArchitecture(
message =
"This method will be deprecated later as part of Stable APIs with bridge removal and not"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.uimanager.events.EventDispatcherProvider;
import java.lang.reflect.InvocationHandler;
Expand Down Expand Up @@ -169,6 +170,11 @@ public void handleException(Exception e) {
mReactHost.handleHostException(e);
}

@Override
public @Nullable CallInvokerHolder getJSCallInvokerHolder() {
return mReactHost.getJSCallInvokerHolder();
}

DefaultHardwareBackBtnHandler getDefaultHardwareBackBtnHandler() {
return mReactHost.getDefaultBackButtonHandler();
}
Expand Down

0 comments on commit 69bb4fc

Please sign in to comment.