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

Reviewed By: mdvacca

Differential Revision: D60100756
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Jul 28, 2024
1 parent 329ab64 commit 880318c
Show file tree
Hide file tree
Showing 28 changed files with 176 additions and 78 deletions.
1 change: 0 additions & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,6 @@ public 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 enableEagerRootViewAttachment Z
public static field enableFabricLogs Z
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 @@ -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;

// Lazy Props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,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<<ca939ab47fa68fbb5acf5ea34481def9>>
* @generated SignedSource<<56adda271bcc179b28ee274516621130>>
*/

/**
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<<2a8d5ca8a0ac46b4d3177cb8b12ad7ac>>
* @generated SignedSource<<55c12cd940ea93972522deb07da4c4f7>>
*/

/**
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 @@ -130,6 +131,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<<aaf205098eaac9171aa15bc8f7bda805>>
* @generated SignedSource<<2c4f316e012720c438a96abf6a4939b0>>
*/

/**
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<<fc363737bfe42515306043b836820f3f>>
* @generated SignedSource<<a20c88cf9d1d04490bc78630ac70ccc1>>
*/

/**
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<<82f6d4eda4011bee81810af366f5d677>>
* @generated SignedSource<<c764ec599b576cf412f62e910e82bd15>>
*/

/**
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 @@ -142,6 +143,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<<ece587d5e6643fb906cfee816824f224>>
* @generated SignedSource<<1fe24c487e564478ff0ec5bcd2431587>>
*/

/**
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 880318c

Please sign in to comment.