Skip to content

Commit

Permalink
Migrate ReactFeatureFlags.enableFabricRenderer -> ReactNativeFeatureF…
Browse files Browse the repository at this point in the history
…lags (facebook#46493)

Summary:
Pull Request resolved: facebook#46493

Migrate:
- ReactFeatureFlags.enableFabricRenderer -> ReactNativeFeatureFlags.enableFabricRenderer()
- ReactFeatureFlags.useTurboModules -> ReactNativeFeatureFlags.useTurboModules()
- Rename ReactFeatureFlags.enableBridgelessArchitecture -> ReactNativeFeatureFlags.enableBridgelessArchitecture()

changelog: [Android][Breaking] Delete useTurboModules, enableFabricRenderer and enableBridgelessArchitecture fields from ReactFeatureFlags class

Reviewed By: rubennorte

Differential Revision: D60364016
  • Loading branch information
mdvacca committed Sep 20, 2024
1 parent 151008f commit 8e17526
Show file tree
Hide file tree
Showing 37 changed files with 453 additions and 178 deletions.
3 changes: 0 additions & 3 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -2041,10 +2041,7 @@ public final class com/facebook/react/common/network/OkHttpCallUtil {

public class com/facebook/react/config/ReactFeatureFlags {
public static field dispatchPointerEvents Z
public static field enableBridgelessArchitecture Z
public static field enableCppPropsIteratorSetter Z
public static field enableFabricRenderer Z
public static field useTurboModules Z
public fun <init> ()V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.uimanager.ViewManager;
Expand Down Expand Up @@ -73,7 +73,7 @@ private void findNext() {
// This Iterator is used to create the NativeModule registry. The NativeModule
// registry must not have TurboModules. Therefore, if TurboModules are enabled, and
// the current NativeModule is a TurboModule, we need to skip iterating over it.
if (ReactFeatureFlags.useTurboModules && reactModuleInfo.isTurboModule()) {
if (ReactNativeFeatureFlags.useTurboModules() && reactModuleInfo.isTurboModule()) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.jstasks.HeadlessJsTaskConfig;
import com.facebook.react.jstasks.HeadlessJsTaskContext;
import com.facebook.react.jstasks.HeadlessJsTaskEventListener;
Expand Down Expand Up @@ -167,7 +167,7 @@ protected ReactNativeHost getReactNativeHost() {
}

protected ReactContext getReactContext() {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
ReactHost reactHost = getReactHost();
Assertions.assertNotNull(reactHost, "getReactHost() is null in New Architecture");
return reactHost.getCurrentReactContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.Callback;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.modules.core.PermissionListener;

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ public void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isWideColorGamutEnabled()) {
mActivity.getWindow().setColorMode(ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT);
}
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactDelegate =
new ReactDelegate(getPlainActivity(), getReactHost(), mainComponentName, launchOptions);
} else {
Expand Down Expand Up @@ -226,7 +226,7 @@ protected Activity getPlainActivity() {
* @return true if Fabric is enabled for this Activity, false otherwise.
*/
protected boolean isFabricEnabled() {
return ReactFeatureFlags.enableFabricRenderer;
return ReactNativeFeatureFlags.enableFabricRenderer();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.devsupport.DoubleTapReloadRecognizer;
import com.facebook.react.devsupport.ReleaseDevSupportManager;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.interfaces.fabric.ReactSurface;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;

/**
Expand All @@ -43,7 +43,7 @@ public class ReactDelegate {

@Nullable private ReactSurface mReactSurface;

private boolean mFabricEnabled = ReactFeatureFlags.enableFabricRenderer;
private boolean mFabricEnabled = ReactNativeFeatureFlags.enableFabricRenderer();

/**
* Do not use this constructor as it's not accounting for New Architecture at all. You should
Expand Down Expand Up @@ -94,7 +94,7 @@ public ReactDelegate(

@Nullable
private DevSupportManager getDevSupportManager() {
if (ReactFeatureFlags.enableBridgelessArchitecture
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()
&& mReactHost != null
&& mReactHost.getDevSupportManager() != null) {
return mReactHost.getDevSupportManager();
Expand All @@ -111,7 +111,7 @@ public void onHostResume() {
throw new ClassCastException(
"Host Activity does not implement DefaultHardwareBackBtnHandler");
}
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onHostResume(mActivity, (DefaultHardwareBackBtnHandler) mActivity);
} else {
if (getReactNativeHost().hasInstance()) {
Expand All @@ -123,7 +123,7 @@ public void onHostResume() {
}

public void onUserLeaveHint() {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onHostLeaveHint(mActivity);
} else {
if (getReactNativeHost().hasInstance()) {
Expand All @@ -133,7 +133,7 @@ public void onUserLeaveHint() {
}

public void onHostPause() {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onHostPause(mActivity);
} else {
if (getReactNativeHost().hasInstance()) {
Expand All @@ -144,7 +144,7 @@ public void onHostPause() {

public void onHostDestroy() {
unloadApp();
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onHostDestroy(mActivity);
} else {
if (getReactNativeHost().hasInstance()) {
Expand All @@ -154,7 +154,7 @@ public void onHostDestroy() {
}

public boolean onBackPressed() {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onBackPressed();
return true;
} else {
Expand All @@ -167,7 +167,7 @@ public boolean onBackPressed() {
}

public boolean onNewIntent(Intent intent) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onNewIntent(intent);
return true;
} else {
Expand All @@ -181,7 +181,7 @@ public boolean onNewIntent(Intent intent) {

public void onActivityResult(
int requestCode, int resultCode, Intent data, boolean shouldForwardToReactInstance) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onActivityResult(mActivity, requestCode, resultCode, data);
} else {
if (getReactNativeHost().hasInstance() && shouldForwardToReactInstance) {
Expand All @@ -193,7 +193,7 @@ public void onActivityResult(
}

public void onWindowFocusChanged(boolean hasFocus) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onWindowFocusChange(hasFocus);
} else {
if (getReactNativeHost().hasInstance()) {
Expand All @@ -203,7 +203,7 @@ public void onWindowFocusChanged(boolean hasFocus) {
}

public void onConfigurationChanged(Configuration newConfig) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onConfigurationChanged(Assertions.assertNotNull(mActivity));
} else {
if (getReactNativeHost().hasInstance()) {
Expand All @@ -215,7 +215,7 @@ public void onConfigurationChanged(Configuration newConfig) {

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD
&& ((ReactFeatureFlags.enableBridgelessArchitecture
&& ((ReactNativeFeatureFlags.enableBridgelessArchitecture()
&& mReactHost != null
&& mReactHost.getDevSupportManager() != null)
|| (getReactNativeHost().hasInstance()
Expand All @@ -228,7 +228,7 @@ && getReactNativeHost().getUseDeveloperSupport()))) {

public boolean onKeyLongPress(int keyCode) {
if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) {
if (ReactFeatureFlags.enableBridgelessArchitecture && mReactHost != null) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture() && mReactHost != null) {
DevSupportManager devSupportManager = mReactHost.getDevSupportManager();
// onKeyLongPress is a Dev API and not supported in RELEASE mode.
if (devSupportManager != null && !(devSupportManager instanceof ReleaseDevSupportManager)) {
Expand All @@ -254,7 +254,7 @@ public void reload() {
// Reload in RELEASE mode
if (devSupportManager instanceof ReleaseDevSupportManager) {
// Do not reload the bundle from JS as there is no bundler running in release mode.
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
if (mReactHost != null) {
mReactHost.reload("ReactDelegate.reload()");
}
Expand Down Expand Up @@ -286,7 +286,7 @@ public void loadApp() {
*/
public void loadApp(String appKey) {
// With Bridgeless enabled, create and start the surface
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
if (mReactSurface == null) {
// Create a ReactSurface
mReactSurface = mReactHost.createSurface(mActivity, appKey, mLaunchOptions);
Expand All @@ -306,7 +306,7 @@ public void loadApp(String appKey) {

/** Stop the React surface started with {@link ReactDelegate#loadApp()}. */
public void unloadApp() {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
if (mReactSurface != null) {
mReactSurface.stop();
mReactSurface = null;
Expand All @@ -321,7 +321,7 @@ public void unloadApp() {

@Nullable
public ReactRootView getReactRootView() {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
return (ReactRootView) mReactSurface.getView();
} else {
return mReactRootView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import com.facebook.react.common.SurfaceDelegateFactory;
import com.facebook.react.common.annotations.StableReactNativeAPI;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.devsupport.DevSupportManagerFactory;
import com.facebook.react.devsupport.InspectorFlags;
import com.facebook.react.devsupport.ReactInstanceDevHelper;
Expand Down Expand Up @@ -355,7 +354,7 @@ public JavaScriptExecutorFactory getJavaScriptExecutorFactory() {
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
ReactRootView rootView = new ReactRootView(currentActivity);
boolean isFabric = ReactFeatureFlags.enableFabricRenderer;
boolean isFabric = ReactNativeFeatureFlags.enableFabricRenderer();
rootView.setIsFabric(isFabric);
rootView.startReactApplication(ReactInstanceManager.this, appKey, new Bundle());
return rootView;
Expand Down Expand Up @@ -1470,7 +1469,7 @@ private ReactApplicationContext createReactContext(
// architecture so it will always be there.
catalystInstance.getRuntimeScheduler();

if (ReactFeatureFlags.useTurboModules && mTMMDelegateBuilder != null) {
if (ReactNativeFeatureFlags.useTurboModules() && mTMMDelegateBuilder != null) {
TurboModuleManagerDelegate tmmDelegate =
mTMMDelegateBuilder
.setPackages(mPackages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.internal.turbomodule.core.TurboModuleManagerDelegate;
import com.facebook.react.module.annotations.ReactModule;
Expand All @@ -37,7 +36,7 @@ interface ModuleProvider {
new HashMap<>();

private final boolean mShouldEnableLegacyModuleInterop =
ReactFeatureFlags.enableBridgelessArchitecture
ReactNativeFeatureFlags.enableBridgelessArchitecture()
&& ReactNativeFeatureFlags.useTurboModuleInterop();

// Lazy Props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.internal.turbomodule.core.interfaces.TurboModuleRegistry;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
Expand Down Expand Up @@ -459,7 +459,7 @@ public <T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface
}

private TurboModuleRegistry getTurboModuleRegistry() {
if (ReactFeatureFlags.useTurboModules) {
if (ReactNativeFeatureFlags.useTurboModules()) {
return Assertions.assertNotNull(
mTurboModuleRegistry,
"TurboModules are enabled, but mTurboModuleRegistry hasn't been set.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import androidx.annotation.Nullable;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import java.util.HashMap;

Expand Down Expand Up @@ -52,6 +51,7 @@ public <T extends JavaScriptModule> void registerInteropModule(
}

private boolean checkReactFeatureFlagsConditions() {
return ReactFeatureFlags.enableFabricRenderer && ReactNativeFeatureFlags.useFabricInterop();
return ReactNativeFeatureFlags.enableFabricRenderer()
&& ReactNativeFeatureFlags.useFabricInterop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,6 @@
@Deprecated(since = "Use com.facebook.react.internal.featureflags.ReactNativeFeatureFlags instead.")
@DoNotStripAny
public class ReactFeatureFlags {
/**
* Should this application use TurboModules? If yes, then any module that inherits {@link
* com.facebook.react.turbomodule.core.interfaces.TurboModule} will NOT be passed in to C++
* CatalystInstanceImpl
*/
@Deprecated(
since =
"useTurboModules will be deleted in 0.77, please use"
+ " DefaultNewArchitectureEntryPoint.load() to enable TurboModules instead.",
forRemoval = true)
public static volatile boolean useTurboModules = false;

/**
* Should this application use the new (Fabric) Renderer? If yes, all rendering in this app will
* use Fabric instead of the legacy renderer.
*/
@Deprecated(
since =
"enableFabricRenderer will be deleted in 0.77, please use"
+ " DefaultNewArchitectureEntryPoint.load() to enable fabric instead.",
forRemoval = true)
public static volatile boolean enableFabricRenderer = false;

/**
* Feature flag to enable the new bridgeless architecture. Note: Enabling this will force enable
* the following flags: `useTurboModules` & `enableFabricRenderer`.
*/
@Deprecated(
since =
"enableBridgelessArchitecture will be deleted in 0.77, please use"
+ " DefaultNewArchitectureEntryPoint.load() to enable bridgeless architecture"
+ " instead.",
forRemoval = true)
public static boolean enableBridgelessArchitecture = false;

public static boolean dispatchPointerEvents = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package com.facebook.react.defaults

import com.facebook.react.common.annotations.VisibleForTesting
import com.facebook.react.config.ReactFeatureFlags
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlagsDefaults

Expand Down Expand Up @@ -39,18 +38,20 @@ public object DefaultNewArchitectureEntryPoint {
if (!isValid) {
error(errorMessage)
}
ReactFeatureFlags.useTurboModules = turboModulesEnabled
ReactFeatureFlags.enableFabricRenderer = fabricEnabled

if (bridgelessEnabled) {
ReactNativeFeatureFlags.override(
object : ReactNativeNewArchitectureFeatureFlagsDefaults() {
override fun useFabricInterop(): Boolean = fabricEnabled

override fun enableFabricRenderer(): Boolean = fabricEnabled

// We turn this feature flag to true for OSS to fix #44610 and #45126 and other
// similar bugs related to pressable.
override fun enableEventEmitterRetentionDuringGesturesOnAndroid(): Boolean =
fabricEnabled

override fun useTurboModules(): Boolean = turboModulesEnabled
})
}

Expand Down
Loading

0 comments on commit 8e17526

Please sign in to comment.