Skip to content

Commit bfdfba1

Browse files
javachefacebook-github-bot
authored andcommitted
Expose RuntimeExecutor on ReactContext (#56987)
Summary: Add `ReactContext.getRuntimeExecutor()` so callers can obtain the `RuntimeExecutor` without reaching into `CatalystInstance`. The bridge subclass forwards to `CatalystInstance.getRuntimeExecutor()`; the bridgeless subclass forwards to `ReactHost.runtimeExecutor`; `ThemedReactContext` proxies to its wrapped `ReactApplicationContext`. Previously, callers that needed the runtime executor had to reach through `catalystInstance.getRuntimeExecutor()`, which is bridge-only and required a `NoGetCatalystInstance` lint suppression. The new accessor works uniformly in both bridged and bridgeless modes. Changelog: [Android][Added] - Add `ReactContext.getRuntimeExecutor()` Reviewed By: mdvacca Differential Revision: D106647233
1 parent f363f6b commit bfdfba1

5 files changed

Lines changed: 16 additions & 0 deletions

File tree

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ public abstract class com/facebook/react/bridge/ReactContext : android/content/C
967967
public abstract fun getNativeModule (Ljava/lang/String;)Lcom/facebook/react/bridge/NativeModule;
968968
public abstract fun getNativeModules ()Ljava/util/Collection;
969969
public fun getNativeModulesMessageQueueThread ()Lcom/facebook/react/bridge/queue/MessageQueueThread;
970+
public abstract fun getRuntimeExecutor ()Lcom/facebook/react/bridge/RuntimeExecutor;
970971
public fun getScrollEndedListeners ()Lcom/facebook/react/bridge/ScrollEndedListeners;
971972
public abstract fun getSourceURL ()Ljava/lang/String;
972973
public fun getSystemService (Ljava/lang/String;)Ljava/lang/Object;
@@ -4162,6 +4163,7 @@ public final class com/facebook/react/uimanager/ThemedReactContext : com/faceboo
41624163
public fun getNativeModule (Ljava/lang/String;)Lcom/facebook/react/bridge/NativeModule;
41634164
public fun getNativeModules ()Ljava/util/Collection;
41644165
public final fun getReactApplicationContext ()Lcom/facebook/react/bridge/ReactApplicationContext;
4166+
public fun getRuntimeExecutor ()Lcom/facebook/react/bridge/RuntimeExecutor;
41654167
public fun getScrollEndedListeners ()Lcom/facebook/react/bridge/ScrollEndedListeners;
41664168
public fun getSourceURL ()Ljava/lang/String;
41674169
public final fun getSurfaceID ()Ljava/lang/String;

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/BridgeReactContext.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,6 @@ public open class BridgeReactContext(context: Context) : ReactApplicationContext
282282
private const val LATE_NATIVE_MODULE_EXCEPTION_MESSAGE: String =
283283
"Trying to call native module after CatalystInstance has been destroyed!"
284284
}
285+
286+
override fun getRuntimeExecutor(): RuntimeExecutor? = catalystInstance?.runtimeExecutor
285287
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ public LifecycleState getLifecycleState() {
200200
return mLifecycleState;
201201
}
202202

203+
/**
204+
* Returns the {@link RuntimeExecutor} for the underlying JavaScript runtime, or {@code null} if
205+
* the runtime has not been initialized. Works in both bridged and bridgeless modes.
206+
*/
207+
public abstract @Nullable RuntimeExecutor getRuntimeExecutor();
208+
203209
/**
204210
* This allows scroll views to notify NativeAnimatedModule when user-driven scrolling ends.
205211
*

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.facebook.react.bridge.JavaScriptModuleRegistry
2020
import com.facebook.react.bridge.NativeModule
2121
import com.facebook.react.bridge.ReactApplicationContext
2222
import com.facebook.react.bridge.ReactSoftExceptionLogger.logSoftException
23+
import com.facebook.react.bridge.RuntimeExecutor
2324
import com.facebook.react.bridge.UIManager
2425
import com.facebook.react.common.annotations.FrameworkAPI
2526
import com.facebook.react.common.annotations.UnstableReactNativeAPI
@@ -180,4 +181,6 @@ internal class BridgelessReactContext(context: Context, private val reactHost: R
180181
}
181182

182183
override fun getJSCallInvokerHolder(): CallInvokerHolder? = reactHost.jsCallInvokerHolder
184+
185+
override fun getRuntimeExecutor(): RuntimeExecutor? = reactHost.runtimeExecutor
183186
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ThemedReactContext.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.facebook.react.bridge.LifecycleEventListener
2020
import com.facebook.react.bridge.NativeModule
2121
import com.facebook.react.bridge.ReactApplicationContext
2222
import com.facebook.react.bridge.ReactContext
23+
import com.facebook.react.bridge.RuntimeExecutor
2324
import com.facebook.react.bridge.ScrollEndedListeners
2425
import com.facebook.react.bridge.UIManager
2526
import com.facebook.react.common.annotations.internal.LegacyArchitecture
@@ -162,6 +163,8 @@ public class ThemedReactContext(
162163
override fun getJSCallInvokerHolder(): CallInvokerHolder? =
163164
reactApplicationContext.getJSCallInvokerHolder()
164165

166+
override fun getRuntimeExecutor(): RuntimeExecutor? = reactApplicationContext.runtimeExecutor
167+
165168
@Deprecated(
166169
"This method is deprecated, please use UIManagerHelper.getUIManager() instead.",
167170
ReplaceWith("UIManagerHelper.getUIManager()"),

0 commit comments

Comments
 (0)