Skip to content

Commit

Permalink
Migrate enableBridgelessArchitecture to ReactNativeFeatureFlags (face…
Browse files Browse the repository at this point in the history
…book#45611)

Summary:
Pull Request resolved: facebook#45611

Migrate enableBridgelessArchitecture to ReactNativeFeatureFlags

changelog: [internal] internal

Differential Revision: D60100756
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Jul 23, 2024
1 parent bb23026 commit 8d2cc67
Show file tree
Hide file tree
Showing 27 changed files with 181 additions and 76 deletions.
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 @@ -171,7 +171,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 @@ -19,6 +19,7 @@
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 +108,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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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 Down Expand Up @@ -94,7 +95,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 +112,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 +124,7 @@ public void onHostResume() {
}

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

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

public void onHostDestroy() {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
if (mReactSurface != null) {
mReactSurface.stop();
mReactSurface = null;
Expand All @@ -161,7 +162,7 @@ public void onHostDestroy() {
}

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

public boolean onNewIntent(Intent intent) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onNewIntent(intent);
return true;
} else {
Expand All @@ -188,7 +189,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 @@ -200,7 +201,7 @@ public void onActivityResult(
}

public void onWindowFocusChanged(boolean hasFocus) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactHost.onWindowFocusChange(hasFocus);
} else {
if (getReactNativeHost().hasInstance()) {
Expand All @@ -210,7 +211,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 @@ -222,7 +223,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 @@ -235,7 +236,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 @@ -261,7 +262,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 All @@ -287,7 +288,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 +307,7 @@ public void loadApp(String appKey) {
}

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 @@ -15,6 +15,7 @@
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;
import com.facebook.react.module.model.ReactModuleInfo;
Expand All @@ -36,7 +37,7 @@ interface ModuleProvider {
new HashMap<>();

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

private final boolean mEnableTurboModuleSyncVoidMethods =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public class ReactFeatureFlags {
*/
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`.
*/
public static boolean enableBridgelessArchitecture = false;

/**
* Should this application enable the Fabric Interop Layer for Android? If yes, the application
* will behave so that it can accept non-Fabric components and render them on Fabric. This toggle
Expand All @@ -52,12 +58,6 @@ public class ReactFeatureFlags {
*/
public static volatile boolean unstable_useFabricInterop = false;

/**
* Feature flag to enable the new bridgeless architecture. Note: Enabling this will force enable
* the following flags: `useTurboModules` & `enableFabricRenderer`.
*/
public static boolean enableBridgelessArchitecture = false;

/** This feature flag enables logs for Fabric */
public static boolean enableFabricLogs = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public object DefaultNewArchitectureEntryPoint {
ReactFeatureFlags.useTurboModules = turboModulesEnabled
ReactFeatureFlags.enableFabricRenderer = fabricEnabled
ReactFeatureFlags.unstable_useFabricInterop = fabricEnabled
ReactFeatureFlags.enableBridgelessArchitecture = bridgelessEnabled
ReactFeatureFlags.unstable_useTurboModuleInterop = bridgelessEnabled
val fuseboxEnabledDebug = fuseboxEnabled

Expand All @@ -54,6 +53,8 @@ public object DefaultNewArchitectureEntryPoint {

override fun enableMicrotasks(): Boolean = true

override fun enableBridgelessArchitecture(): Boolean = bridgelessEnabled

override fun batchRenderingUpdatesInEventLoop(): Boolean = true

override fun useNativeViewConfigsInBridgelessMode(): Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public void invalidate() {
// responsible for initializing and deallocating EventDispatcher. StaticViewConfigs is enabled
// only in Bridgeless for now.
// TODO T83943316: Remove this IF once StaticViewConfigs are enabled by default
if (!ReactFeatureFlags.enableBridgelessArchitecture) {
if (!ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mEventDispatcher.onCatalystInstanceDestroyed();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<4a2baeeff0b03f07a259028cf4446455>>
* @generated SignedSource<<93a8869f0714b3c8913ceba6a7c4056a>>
*/

/**
Expand Down Expand Up @@ -76,6 +76,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun enableAlignItemsBaselineOnFabricIOS(): Boolean = accessor.enableAlignItemsBaselineOnFabricIOS()

/**
* Enables the Bridgeless Architecture. Note: Enabling this will force enable the following flags: `useTurboModules` & `enableFabricRenderer`
*/
@JvmStatic
public fun enableBridgelessArchitecture(): Boolean = accessor.enableBridgelessArchitecture()

/**
* Clean yoga node when <TextInput /> does not change.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<7fbe53bfb2b06cdae8b1590c9131edbb>>
* @generated SignedSource<<7e74e4f03693eb883b563bf3bcefaeb0>>
*/

/**
Expand All @@ -28,6 +28,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var completeReactInstanceCreationOnBgThreadOnAndroidCache: Boolean? = null
private var destroyFabricSurfacesInReactInstanceManagerCache: Boolean? = null
private var enableAlignItemsBaselineOnFabricIOSCache: Boolean? = null
private var enableBridgelessArchitectureCache: Boolean? = null
private var enableCleanTextInputYogaNodeCache: Boolean? = null
private var enableFabricRendererExclusivelyCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
Expand Down Expand Up @@ -129,6 +130,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}

override fun enableBridgelessArchitecture(): Boolean {
var cached = enableBridgelessArchitectureCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.enableBridgelessArchitecture()
enableBridgelessArchitectureCache = cached
}
return cached
}

override fun enableCleanTextInputYogaNode(): Boolean {
var cached = enableCleanTextInputYogaNodeCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<df4c04351e9713db7de1ecf4d8f8d435>>
* @generated SignedSource<<b9644d42a88a96de0fc5ed9a925d58fa>>
*/

/**
Expand Down Expand Up @@ -44,6 +44,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun enableAlignItemsBaselineOnFabricIOS(): Boolean

@DoNotStrip @JvmStatic public external fun enableBridgelessArchitecture(): Boolean

@DoNotStrip @JvmStatic public external fun enableCleanTextInputYogaNode(): Boolean

@DoNotStrip @JvmStatic public external fun enableFabricRendererExclusively(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<fcab38c9de5314e55ff64584b9221b9c>>
* @generated SignedSource<<36ce43a58cd2608672ce4f8a475e26ad>>
*/

/**
Expand Down Expand Up @@ -39,6 +39,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun enableAlignItemsBaselineOnFabricIOS(): Boolean = true

override fun enableBridgelessArchitecture(): Boolean = false

override fun enableCleanTextInputYogaNode(): Boolean = false

override fun enableFabricRendererExclusively(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c740d546d8154130aeabdd3667c26473>>
* @generated SignedSource<<483b7237b8b64398625d8ca203fe18dc>>
*/

/**
Expand Down Expand Up @@ -32,6 +32,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var completeReactInstanceCreationOnBgThreadOnAndroidCache: Boolean? = null
private var destroyFabricSurfacesInReactInstanceManagerCache: Boolean? = null
private var enableAlignItemsBaselineOnFabricIOSCache: Boolean? = null
private var enableBridgelessArchitectureCache: Boolean? = null
private var enableCleanTextInputYogaNodeCache: Boolean? = null
private var enableFabricRendererExclusivelyCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
Expand Down Expand Up @@ -141,6 +142,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun enableBridgelessArchitecture(): Boolean {
var cached = enableBridgelessArchitectureCache
if (cached == null) {
cached = currentProvider.enableBridgelessArchitecture()
accessedFeatureFlags.add("enableBridgelessArchitecture")
enableBridgelessArchitectureCache = cached
}
return cached
}

override fun enableCleanTextInputYogaNode(): Boolean {
var cached = enableCleanTextInputYogaNodeCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c3138a9a6b90f5a35bcdda2928b759ed>>
* @generated SignedSource<<9c33a97e7e8c6917eeaab8bedf599995>>
*/

/**
Expand Down Expand Up @@ -39,6 +39,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun enableAlignItemsBaselineOnFabricIOS(): Boolean

@DoNotStrip public fun enableBridgelessArchitecture(): Boolean

@DoNotStrip public fun enableCleanTextInputYogaNode(): Boolean

@DoNotStrip public fun enableFabricRendererExclusively(): Boolean
Expand Down
Loading

0 comments on commit 8d2cc67

Please sign in to comment.