Skip to content

Commit 124ced5

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Remove non-bridgeless code paths from ReactDelegate / ReactActivityDelegate / ReactActivity / ReactFragment
Summary: Third in a stack that collapses Android-side branches on `ReactNativeNewArchitectureFeatureFlags.enableBridgelessArchitecture()` under the standing assumption that on Android the flag is always `true`. The underlying generated `ReactNativeFeatureFlags.enableBridgelessArchitecture()` is untouched. This is the cascade cleanup: with every lifecycle method in `ReactDelegate` always taking the `ReactHost` path, the fields, constructors, and helper methods that exist only to support the `ReactNativeHost`/`ReactInstanceManager` (bridge) path are now dead. Removed from `ReactDelegate`: - The deprecated 4-arg `(Activity, ReactNativeHost?, String?, Bundle?)` constructor - The deprecated 5-arg `(Activity, ReactNativeHost?, String?, Bundle?, Boolean)` constructor - `getReactInstanceManager()` (was reading through the removed `ReactNativeHost`) - `createRootView()` (only the legacy `loadApp` branch called it) - `isFabricEnabled` (only `createRootView` read it) - `internalReactRootView` field and the corresponding `reactRootView` setter (the property is now a `val` returning `reactSurface?.view`) - The private `reactNativeHost` field Every public lifecycle method (`onHostResume`, `onUserLeaveHint`, `onHostPause`, `onHostDestroy`, `onBackPressed`, `onNewIntent`, `onActivityResult`, `onWindowFocusChanged`, `onConfigurationChanged`, `onKeyDown`, `onKeyLongPress`, `reload`, `loadApp`, `unloadApp`, `currentReactContext`) collapses to the `ReactHost`-only path. Removed from `ReactActivityDelegate`: - `getReactNativeHost()` and `getReactInstanceManager()` (both deprecated, fed the dead `ReactDelegate` machinery) - `setReactRootView(ReactRootView)` (matched the removed `ReactDelegate.reactRootView` setter) - The non-bridgeless branch in `onCreate` (the anonymous-subclass override of `createRootView` goes with it) - The non-bridgeless branch in `onRequestPermissionsResult` Removed from `ReactActivity`: - `getReactNativeHost()` and `getReactInstanceManager()` (matched the delegate removals) Removed from `ReactFragment`: - The `reactNativeHost` property - The non-bridgeless branch in `onCreate` (the `ARG_FABRIC_ENABLED` argument is now ignored; the constant + Builder API remain for backward compatibility) `ReactAndroid.api` regenerated to reflect the 12 removed public/protected methods. `arc f` auto-removed the now-unused `ReactNativeNewArchitectureFeatureFlags` imports. Subsequent diff in the stack will handle the wrapper method + lint detector. Changelog: [Android][Breaking] - Remove deprecated `ReactDelegate(Activity, ReactNativeHost, String, Bundle)` and `ReactDelegate(Activity, ReactNativeHost, String, Bundle, boolean)` constructors. Use the `ReactHost` constructor instead. [Android][Breaking] - Remove `ReactDelegate.getReactInstanceManager()`, `ReactDelegate.createRootView()`, `ReactDelegate.isFabricEnabled`, and the `ReactDelegate.reactRootView` setter. [Android][Breaking] - Remove `ReactActivityDelegate.getReactNativeHost()`, `ReactActivityDelegate.getReactInstanceManager()`, and `ReactActivityDelegate.setReactRootView(ReactRootView)`. Use `getReactHost()` and `setReactSurface(ReactSurface)` instead. [Android][Breaking] - Remove `ReactActivity.getReactNativeHost()` and `ReactActivity.getReactInstanceManager()`. Use `getReactHost()` instead. [Android][Breaking] - Remove `ReactFragment.reactNativeHost` property. Use `reactHost` instead. Reviewed By: christophpurrer Differential Revision: D106719840
1 parent d77ccbe commit 124ced5

5 files changed

Lines changed: 47 additions & 402 deletions

File tree

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ public abstract class com/facebook/react/ReactActivity : androidx/appcompat/app/
6565
public fun getReactActivityDelegate ()Lcom/facebook/react/ReactActivityDelegate;
6666
public fun getReactDelegate ()Lcom/facebook/react/ReactDelegate;
6767
protected fun getReactHost ()Lcom/facebook/react/ReactHost;
68-
protected final fun getReactInstanceManager ()Lcom/facebook/react/ReactInstanceManager;
69-
protected final fun getReactNativeHost ()Lcom/facebook/react/ReactNativeHost;
7068
public fun invokeDefaultOnBackPressed ()V
7169
protected final fun loadApp (Ljava/lang/String;)V
7270
public fun onActivityResult (IILandroid/content/Intent;)V
@@ -99,8 +97,6 @@ public class com/facebook/react/ReactActivityDelegate {
9997
protected fun getReactActivity ()Lcom/facebook/react/ReactActivity;
10098
protected fun getReactDelegate ()Lcom/facebook/react/ReactDelegate;
10199
public fun getReactHost ()Lcom/facebook/react/ReactHost;
102-
public fun getReactInstanceManager ()Lcom/facebook/react/ReactInstanceManager;
103-
protected fun getReactNativeHost ()Lcom/facebook/react/ReactNativeHost;
104100
protected fun isFabricEnabled ()Z
105101
protected fun isWideColorGamutEnabled ()Z
106102
protected fun loadApp (Ljava/lang/String;)V
@@ -119,7 +115,6 @@ public class com/facebook/react/ReactActivityDelegate {
119115
public fun onUserLeaveHint ()V
120116
public fun onWindowFocusChanged (Z)V
121117
public fun requestPermissions ([Ljava/lang/String;ILcom/facebook/react/modules/core/PermissionListener;)V
122-
public fun setReactRootView (Lcom/facebook/react/ReactRootView;)V
123118
public fun setReactSurface (Lcom/facebook/react/interfaces/fabric/ReactSurface;)V
124119
}
125120

@@ -130,14 +125,9 @@ public abstract interface class com/facebook/react/ReactApplication {
130125

131126
public class com/facebook/react/ReactDelegate {
132127
public fun <init> (Landroid/app/Activity;Lcom/facebook/react/ReactHost;Ljava/lang/String;Landroid/os/Bundle;)V
133-
public fun <init> (Landroid/app/Activity;Lcom/facebook/react/ReactNativeHost;Ljava/lang/String;Landroid/os/Bundle;)V
134-
public fun <init> (Landroid/app/Activity;Lcom/facebook/react/ReactNativeHost;Ljava/lang/String;Landroid/os/Bundle;Z)V
135-
protected fun createRootView ()Lcom/facebook/react/ReactRootView;
136128
public final fun getCurrentReactContext ()Lcom/facebook/react/bridge/ReactContext;
137129
public final fun getReactHost ()Lcom/facebook/react/ReactHost;
138-
public final fun getReactInstanceManager ()Lcom/facebook/react/ReactInstanceManager;
139130
public final fun getReactRootView ()Lcom/facebook/react/ReactRootView;
140-
protected final fun isFabricEnabled ()Z
141131
public final fun loadApp ()V
142132
public final fun loadApp (Ljava/lang/String;)V
143133
public final fun onActivityResult (IILandroid/content/Intent;Z)V
@@ -152,7 +142,6 @@ public class com/facebook/react/ReactDelegate {
152142
public final fun onUserLeaveHint ()V
153143
public final fun onWindowFocusChanged (Z)V
154144
public final fun reload ()V
155-
public final fun setReactRootView (Lcom/facebook/react/ReactRootView;)V
156145
public final fun setReactSurface (Lcom/facebook/react/interfaces/fabric/ReactSurface;)V
157146
public final fun shouldShowDevMenuOrReload (ILandroid/view/KeyEvent;)Z
158147
public final fun unloadApp ()V
@@ -170,7 +159,6 @@ public class com/facebook/react/ReactFragment : androidx/fragment/app/Fragment,
170159
public fun checkSelfPermission (Ljava/lang/String;)I
171160
protected final fun getReactDelegate ()Lcom/facebook/react/ReactDelegate;
172161
protected fun getReactHost ()Lcom/facebook/react/ReactHost;
173-
protected fun getReactNativeHost ()Lcom/facebook/react/ReactNativeHost;
174162
public fun onActivityResult (IILandroid/content/Intent;)V
175163
public fun onBackPressed ()Z
176164
public fun onCreate (Landroid/os/Bundle;)V

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,10 @@ public void onConfigurationChanged(@NotNull Configuration newConfig) {
167167
mDelegate.onConfigurationChanged(newConfig);
168168
}
169169

170-
protected final ReactNativeHost getReactNativeHost() {
171-
return mDelegate.getReactNativeHost();
172-
}
173-
174170
protected ReactHost getReactHost() {
175171
return mDelegate.getReactHost();
176172
}
177173

178-
protected final ReactInstanceManager getReactInstanceManager() {
179-
return mDelegate.getReactInstanceManager();
180-
}
181-
182174
protected final void loadApp(String appKey) {
183175
mDelegate.loadApp(appKey);
184176
}

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

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.facebook.react.bridge.ReactContext;
2424
import com.facebook.react.common.LifecycleState;
2525
import com.facebook.react.interfaces.fabric.ReactSurface;
26-
import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags;
2726
import com.facebook.react.modules.core.PermissionListener;
2827
import com.facebook.react.views.view.WindowUtilKt;
2928
import com.facebook.systrace.Systrace;
@@ -83,21 +82,6 @@ public ReactActivityDelegate(
8382
return null;
8483
}
8584

86-
/**
87-
* Get the {@link ReactNativeHost} used by this app with Bridge enabled. By default, assumes
88-
* {@link Activity#getApplication()} is an instance of {@link ReactApplication} and calls {@link
89-
* ReactApplication#getReactNativeHost()}. Override this method if your application class does not
90-
* implement {@code ReactApplication} or you simply have a different mechanism for storing a
91-
* {@code ReactNativeHost}, e.g. as a static field somewhere.
92-
*
93-
* @deprecated "Do not access {@link ReactNativeHost} directly. This class is going away in the
94-
* New Architecture. You should access {@link ReactHost} instead."
95-
*/
96-
@Deprecated
97-
protected ReactNativeHost getReactNativeHost() {
98-
return ((ReactApplication) getPlainActivity().getApplication()).getReactNativeHost();
99-
}
100-
10185
/**
10286
* Get the {@link ReactHost} used by this app with Bridgeless enabled. By default, assumes {@link
10387
* Activity#getApplication()} is an instance of {@link ReactApplication} and calls {@link
@@ -113,16 +97,6 @@ protected ReactNativeHost getReactNativeHost() {
11397
return mReactDelegate;
11498
}
11599

116-
/**
117-
* @deprecated @deprecated "Do not access {@link ReactInstanceManager} directly. This class is
118-
* going away in the New Architecture. You should access {@link ReactHost} instead."
119-
* @noinspection deprecation
120-
*/
121-
@Deprecated
122-
public ReactInstanceManager getReactInstanceManager() {
123-
return Objects.requireNonNull(mReactDelegate).getReactInstanceManager();
124-
}
125-
126100
@Nullable
127101
public String getMainComponentName() {
128102
return mMainComponentName;
@@ -144,29 +118,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
144118
}
145119
}
146120
}
147-
if (ReactNativeNewArchitectureFeatureFlags.enableBridgelessArchitecture()) {
148-
mReactDelegate =
149-
new ReactDelegate(
150-
getPlainActivity(), getReactHost(), mainComponentName, launchOptions);
151-
} else {
152-
mReactDelegate =
153-
new ReactDelegate(
154-
getPlainActivity(),
155-
getReactNativeHost(),
156-
mainComponentName,
157-
launchOptions,
158-
isFabricEnabled()) {
159-
@Override
160-
@Nullable
161-
protected ReactRootView createRootView() {
162-
ReactRootView rootView = ReactActivityDelegate.this.createRootView();
163-
if (rootView == null) {
164-
rootView = super.createRootView();
165-
}
166-
return rootView;
167-
}
168-
};
169-
}
121+
mReactDelegate =
122+
new ReactDelegate(
123+
getPlainActivity(), getReactHost(), mainComponentName, launchOptions);
170124
if (mainComponentName != null) {
171125
loadApp(mainComponentName);
172126
}
@@ -182,10 +136,6 @@ public void setReactSurface(ReactSurface reactSurface) {
182136
Objects.requireNonNull(mReactDelegate).setReactSurface(reactSurface);
183137
}
184138

185-
public void setReactRootView(ReactRootView reactRootView) {
186-
Objects.requireNonNull(mReactDelegate).setReactRootView(reactRootView);
187-
}
188-
189139
public void onUserLeaveHint() {
190140
Objects.requireNonNull(mReactDelegate).onUserLeaveHint();
191141
}
@@ -256,18 +206,9 @@ public void onRequestPermissionsResult(
256206
}
257207
};
258208

259-
LifecycleState lifecycle;
260-
if (isFabricEnabled()) {
261-
ReactHost reactHost = getReactHost();
262-
lifecycle = reactHost != null ? reactHost.getLifecycleState() : LifecycleState.BEFORE_CREATE;
263-
} else {
264-
ReactNativeHost reactNativeHost = getReactNativeHost();
265-
if (!reactNativeHost.hasInstance()) {
266-
lifecycle = LifecycleState.BEFORE_CREATE;
267-
} else {
268-
lifecycle = reactNativeHost.getReactInstanceManager().getLifecycleState();
269-
}
270-
}
209+
ReactHost reactHost = getReactHost();
210+
LifecycleState lifecycle =
211+
reactHost != null ? reactHost.getLifecycleState() : LifecycleState.BEFORE_CREATE;
271212

272213
// If the permission request didn't show a dialog to the user, we can call the callback
273214
// immediately.

0 commit comments

Comments
 (0)