From 870095b076e4529a5cc71787e28f6355a2bb05db Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Fri, 22 Mar 2024 13:23:49 -0700 Subject: [PATCH] Make ReactContext and ReactApplicationContext classes abstract (#43625) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43625 Changelog: [Android][Breaking] Make ReactApplicationContext and ReactContext abstract. Please instantiate BridgeReactContext instead (bridge mode). Or BridgelessReactContext instead (bridgeless mode). Reviewed By: arushikesarwani94 Differential Revision: D55218590 --- packages/react-native/ReactAndroid/api/ReactAndroid.api | 4 ++-- .../com/facebook/react/bridge/ReactApplicationContext.java | 2 +- .../src/main/java/com/facebook/react/bridge/ReactContext.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 6e2698c4b93995..b8512e542a0735 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -1056,7 +1056,7 @@ public class com/facebook/react/bridge/ProxyJavaScriptExecutor$Factory : com/fac public fun stopSamplingProfiler (Ljava/lang/String;)V } -public class com/facebook/react/bridge/ReactApplicationContext : com/facebook/react/bridge/ReactContext { +public abstract class com/facebook/react/bridge/ReactApplicationContext : com/facebook/react/bridge/ReactContext { public fun (Landroid/content/Context;)V } @@ -1068,7 +1068,7 @@ public class com/facebook/react/bridge/ReactBridge { public static fun staticInit ()V } -public class com/facebook/react/bridge/ReactContext : android/content/ContextWrapper { +public abstract class com/facebook/react/bridge/ReactContext : android/content/ContextWrapper { protected field mInteropModuleRegistry Lcom/facebook/react/bridge/interop/InteropModuleRegistry; public fun (Landroid/content/Context;)V public fun addActivityEventListener (Lcom/facebook/react/bridge/ActivityEventListener;)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactApplicationContext.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactApplicationContext.java index 0b8520bf95d39b..ba7dc4536ac784 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactApplicationContext.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactApplicationContext.java @@ -13,7 +13,7 @@ * A context wrapper that always wraps Android Application {@link Context} and {@link * CatalystInstance} by extending {@link ReactContext} */ -public class ReactApplicationContext extends ReactContext { +public abstract class ReactApplicationContext extends ReactContext { // We want to wrap ApplicationContext, since there is no easy way to verify that application // context is passed as a param, we use {@link Context#getApplicationContext} to ensure that // the context we're wrapping is in fact an application context. diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java index 4f5af10bde7056..841368d3d11d0b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java @@ -37,7 +37,7 @@ * Abstract ContextWrapper for Android application or activity {@link Context} and {@link * CatalystInstance} */ -public class ReactContext extends ContextWrapper { +public abstract class ReactContext extends ContextWrapper { @DoNotStrip public interface RCTDeviceEventEmitter extends JavaScriptModule {