Skip to content

Commit

Permalink
Migrate ReactFeatureFlags.enableFabricRenderer -> ReactNativeFeatureF…
Browse files Browse the repository at this point in the history
…lags

Summary:
Migrate ReactFeatureFlags.enableFabricRenderer -> ReactNativeFeatureFlags

changelog: [Android][Breaking] Delete ReactFeatureFlags.enableFabricRenderer API

Reviewed By: cortinico

Differential Revision: D60364016
  • Loading branch information
mdvacca committed Sep 14, 2024
1 parent afb40e9 commit 6bf5a44
Show file tree
Hide file tree
Showing 28 changed files with 189 additions and 98 deletions.
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 @@ -226,7 +227,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 @@ -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 All @@ -43,7 +44,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
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,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
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 @@ -33,17 +33,6 @@ public class ReactFeatureFlags {
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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ public object DefaultNewArchitectureEntryPoint {
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 =
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<<43a7bd07cf5236aa9357e5c1de87151a>>
* @generated SignedSource<<054825206d41eed07d334799f3aadaab>>
*/

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

/**
* Should this application use the new (Fabric) Renderer? If yes, all rendering in this app will use Fabric instead of the legacy renderer.
*/
@JvmStatic
public fun enableFabricRenderer(): Boolean = accessor.enableFabricRenderer()

/**
* When the app is completely migrated to Fabric, set this flag to true to disable parts of Paper infrastructure that are not needed anymore but consume memory and CPU. Specifically, UIViewOperationQueue and EventDispatcherImpl will no longer work as they will not subscribe to ReactChoreographer for updates.
*/
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<<658604b78e381f97e41b0feedb6ff1c3>>
* @generated SignedSource<<b3d27873f7dd053785ebe91241b67202>>
*/

/**
Expand Down Expand Up @@ -34,6 +34,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var enableEagerRootViewAttachmentCache: Boolean? = null
private var enableEventEmitterRetentionDuringGesturesOnAndroidCache: Boolean? = null
private var enableFabricLogsCache: Boolean? = null
private var enableFabricRendererCache: Boolean? = null
private var enableFabricRendererExclusivelyCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
private var enableIOSViewClipToPaddingBoxCache: Boolean? = null
Expand Down Expand Up @@ -198,6 +199,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}

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

override fun enableFabricRendererExclusively(): Boolean {
var cached = enableFabricRendererExclusivelyCache
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<<9b8a7242404f7f1e3c3c6590413db128>>
* @generated SignedSource<<c66e8059d13b925f3cafdda314c14707>>
*/

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

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

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

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

@DoNotStrip @JvmStatic public external fun enableGranularShadowTreeStateReconciliation(): 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<<a8e719f4345d0a526bb62f5f42c4d6c5>>
* @generated SignedSource<<403eb9e5447fae003ffdbf0bf76b813a>>
*/

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

override fun enableFabricLogs(): Boolean = false

override fun enableFabricRenderer(): Boolean = false

override fun enableFabricRendererExclusively(): Boolean = false

override fun enableGranularShadowTreeStateReconciliation(): 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<<8d55bf40875d6544f2d8524035cb773e>>
* @generated SignedSource<<68a1e4af6d21128b389ee65b07d19299>>
*/

/**
Expand Down Expand Up @@ -38,6 +38,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var enableEagerRootViewAttachmentCache: Boolean? = null
private var enableEventEmitterRetentionDuringGesturesOnAndroidCache: Boolean? = null
private var enableFabricLogsCache: Boolean? = null
private var enableFabricRendererCache: Boolean? = null
private var enableFabricRendererExclusivelyCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
private var enableIOSViewClipToPaddingBoxCache: Boolean? = null
Expand Down Expand Up @@ -216,6 +217,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}

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

override fun enableFabricRendererExclusively(): Boolean {
var cached = enableFabricRendererExclusivelyCache
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<<4b0ce21f608338f4c8cb3bb5830b4965>>
* @generated SignedSource<<7b04557d9c1f71edfff416871b76a462>>
*/

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

@DoNotStrip public fun enableFabricLogs(): Boolean

@DoNotStrip public fun enableFabricRenderer(): Boolean

@DoNotStrip public fun enableFabricRendererExclusively(): Boolean

@DoNotStrip public fun enableGranularShadowTreeStateReconciliation(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public open class ReactNativeNewArchitectureFeatureFlagsDefaults(
// Fabric, TurboModules and Bridgeless as enabled by default.
// ReactFeatureFlags is deprecated and will be deleted in 0.77, this code is temporary to
// support the new architecture before 0.77 cut.
ReactFeatureFlags.enableFabricRenderer = true
ReactFeatureFlags.useTurboModules = true
ReactFeatureFlags.enableBridgelessArchitecture = true
}
Expand All @@ -39,5 +38,7 @@ public open class ReactNativeNewArchitectureFeatureFlagsDefaults(

override fun enableMicrotasks(): Boolean = true

override fun enableFabricRenderer(): Boolean = newArchitectureEnabled

override fun useNativeViewConfigsInBridgelessMode(): Boolean = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -135,7 +134,8 @@ private static void validateDirectEventNames(

Map viewManagerBubblingEvents = viewManager.getExportedCustomBubblingEventTypeConstants();
if (viewManagerBubblingEvents != null) {
if (ReactFeatureFlags.enableFabricRenderer && ReactNativeFeatureFlags.useFabricInterop()) {
if (ReactNativeFeatureFlags.enableFabricRenderer()
&& ReactNativeFeatureFlags.useFabricInterop()) {
// For Fabric, events needs to be fired with a "top" prefix.
// For the sake of Fabric Interop, here we normalize events adding "top" in their
// name if the user hasn't provided it.
Expand All @@ -151,7 +151,8 @@ private static void validateDirectEventNames(
Map viewManagerDirectEvents = viewManager.getExportedCustomDirectEventTypeConstants();
validateDirectEventNames(viewManager.getName(), viewManagerDirectEvents);
if (viewManagerDirectEvents != null) {
if (ReactFeatureFlags.enableFabricRenderer && ReactNativeFeatureFlags.useFabricInterop()) {
if (ReactNativeFeatureFlags.enableFabricRenderer()
&& ReactNativeFeatureFlags.useFabricInterop()) {
// For Fabric, events needs to be fired with a "top" prefix.
// For the sake of Fabric Interop, here we normalize events adding "top" in their
// name if the user hasn't provided it.
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<<f87375ebbf889045c449769fdf6018ba>>
* @generated SignedSource<<a552fd2857b795485cdac7c5a19794f3>>
*/

/**
Expand Down Expand Up @@ -123,6 +123,12 @@ class ReactNativeFeatureFlagsProviderHolder
return method(javaProvider_);
}

bool enableFabricRenderer() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableFabricRenderer");
return method(javaProvider_);
}

bool enableFabricRendererExclusively() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableFabricRendererExclusively");
Expand Down Expand Up @@ -419,6 +425,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableFabricLogs(
return ReactNativeFeatureFlags::enableFabricLogs();
}

bool JReactNativeFeatureFlagsCxxInterop::enableFabricRenderer(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableFabricRenderer();
}

bool JReactNativeFeatureFlagsCxxInterop::enableFabricRendererExclusively(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableFabricRendererExclusively();
Expand Down Expand Up @@ -663,6 +674,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"enableFabricLogs",
JReactNativeFeatureFlagsCxxInterop::enableFabricLogs),
makeNativeMethod(
"enableFabricRenderer",
JReactNativeFeatureFlagsCxxInterop::enableFabricRenderer),
makeNativeMethod(
"enableFabricRendererExclusively",
JReactNativeFeatureFlagsCxxInterop::enableFabricRendererExclusively),
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<<dbbc50cc1093a1ce89a10f8679a06846>>
* @generated SignedSource<<996cf32ff8400c043095d97c81e6224c>>
*/

/**
Expand Down Expand Up @@ -72,6 +72,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool enableFabricLogs(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableFabricRenderer(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableFabricRendererExclusively(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Loading

0 comments on commit 6bf5a44

Please sign in to comment.