Migrate ReactFeatureFlags.unstable_useTurboModuleInterop to ReactNativeFeatureFlags (#45697)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45697

Migrate ReactFeatureFlags.unstable_useTurboModuleInterop to ReactNativeFeatureFlags

changelog: [internal] internal

Reviewed By: cortinico

Differential Revision: D60274330

fbshipit-source-id: 64ec9f631b4efcdb5d46859d8d949c3309c54945
This commit is contained in:
David Vacca
2024-07-28 15:12:45 -07:00
committed by Facebook GitHub Bot
parent 484117da09
commit 8d9bdf96f8
23 changed files with 125 additions and 25 deletions
@@ -1983,7 +1983,6 @@ public class com/facebook/react/config/ReactFeatureFlags {
public static field enableCppPropsIteratorSetter Z
public static field enableFabricRenderer Z
public static field enableViewRecycling Z
public static field unstable_useTurboModuleInterop Z
public static field useTurboModules Z
public fun <init> ()V
}
@@ -15,6 +15,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.internal.turbomodule.core.TurboModuleManagerDelegate;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.module.model.ReactModuleInfo;
@@ -37,7 +38,7 @@ public abstract class ReactPackageTurboModuleManagerDelegate extends TurboModule
private final boolean mShouldEnableLegacyModuleInterop =
ReactFeatureFlags.enableBridgelessArchitecture
&& ReactFeatureFlags.unstable_useTurboModuleInterop;
&& ReactNativeFeatureFlags.useTurboModuleInterop();
// Lazy Props
private List<ReactPackage> mPackages;
@@ -28,9 +28,6 @@ public class ReactFeatureFlags {
*/
public static volatile boolean useTurboModules = false;
/** In Bridgeless mode, should legacy NativeModules use the TurboModule system? */
public static volatile boolean unstable_useTurboModuleInterop = false;
/**
* Should this application use the new (Fabric) Renderer? If yes, all rendering in this app will
* use Fabric instead of the legacy renderer.
@@ -43,7 +43,6 @@ public object DefaultNewArchitectureEntryPoint {
ReactFeatureFlags.useTurboModules = turboModulesEnabled
ReactFeatureFlags.enableFabricRenderer = fabricEnabled
ReactFeatureFlags.enableBridgelessArchitecture = bridgelessEnabled
ReactFeatureFlags.unstable_useTurboModuleInterop = bridgelessEnabled
val fuseboxEnabledDebug = fuseboxEnabled
if (bridgelessEnabled) {
@@ -62,6 +61,8 @@ public object DefaultNewArchitectureEntryPoint {
override fun fuseboxEnabledDebug(): Boolean = fuseboxEnabledDebug
override fun useFabricInterop(): Boolean = fabricEnabled
override fun useTurboModuleInterop(): Boolean = bridgelessEnabled
})
}
@@ -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<<8d7ac9ceca277ecef106c8720263555c>>
* @generated SignedSource<<a5a6a0b1b5b0fffc69bb03258aa9f40f>>
*/
/**
@@ -274,6 +274,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun useStateAlignmentMechanism(): Boolean = accessor.useStateAlignmentMechanism()
/**
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
*/
@JvmStatic
public fun useTurboModuleInterop(): Boolean = accessor.useTurboModuleInterop()
/**
* Overrides the feature flags with the ones provided by the given provider
* (generally one that extends `ReactNativeFeatureFlagsDefaults`).
@@ -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<<9ba8cfb856550654e6352d3dc6bcad42>>
* @generated SignedSource<<3f751d1d0f6e07cc778b3716cc9fcc3c>>
*/
/**
@@ -61,6 +61,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var useRuntimeShadowNodeReferenceUpdateCache: Boolean? = null
private var useRuntimeShadowNodeReferenceUpdateOnLayoutCache: Boolean? = null
private var useStateAlignmentMechanismCache: Boolean? = null
private var useTurboModuleInteropCache: Boolean? = null
override fun commonTestFlag(): Boolean {
var cached = commonTestFlagCache
@@ -431,6 +432,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}
override fun useTurboModuleInterop(): Boolean {
var cached = useTurboModuleInteropCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.useTurboModuleInterop()
useTurboModuleInteropCache = cached
}
return cached
}
override fun override(provider: ReactNativeFeatureFlagsProvider): Unit =
ReactNativeFeatureFlagsCxxInterop.override(provider as Any)
@@ -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<<bfac19c73ca5a8461c5ad72143c38d67>>
* @generated SignedSource<<9ab73bca1d6379fe096c26b89495488c>>
*/
/**
@@ -110,6 +110,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
@DoNotStrip @JvmStatic public external fun useStateAlignmentMechanism(): Boolean
@DoNotStrip @JvmStatic public external fun useTurboModuleInterop(): Boolean
@DoNotStrip @JvmStatic public external fun override(provider: Any)
@DoNotStrip @JvmStatic public external fun dangerouslyReset()
@@ -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<<c96668795bd8a623ac1e0ef8332c8329>>
* @generated SignedSource<<c3f3ccc90359ecca8b78f072ad94dd14>>
*/
/**
@@ -104,4 +104,6 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
override fun useRuntimeShadowNodeReferenceUpdateOnLayout(): Boolean = false
override fun useStateAlignmentMechanism(): Boolean = false
override fun useTurboModuleInterop(): Boolean = false
}
@@ -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<<8ea93da64ada6e10f5254f99554933e0>>
* @generated SignedSource<<81072627d7bfbf2b7918921a0e9fe106>>
*/
/**
@@ -65,6 +65,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var useRuntimeShadowNodeReferenceUpdateCache: Boolean? = null
private var useRuntimeShadowNodeReferenceUpdateOnLayoutCache: Boolean? = null
private var useStateAlignmentMechanismCache: Boolean? = null
private var useTurboModuleInteropCache: Boolean? = null
override fun commonTestFlag(): Boolean {
var cached = commonTestFlagCache
@@ -476,6 +477,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}
override fun useTurboModuleInterop(): Boolean {
var cached = useTurboModuleInteropCache
if (cached == null) {
cached = currentProvider.useTurboModuleInterop()
accessedFeatureFlags.add("useTurboModuleInterop")
useTurboModuleInteropCache = cached
}
return cached
}
override fun override(provider: ReactNativeFeatureFlagsProvider) {
if (accessedFeatureFlags.isNotEmpty()) {
val accessedFeatureFlagsStr = accessedFeatureFlags.joinToString(separator = ", ") { it }
@@ -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<<ef8b966ae640e0581c7d7d9b84ce061f>>
* @generated SignedSource<<0224471b80d7ee0c06587f2a563420a5>>
*/
/**
@@ -104,4 +104,6 @@ public interface ReactNativeFeatureFlagsProvider {
@DoNotStrip public fun useRuntimeShadowNodeReferenceUpdateOnLayout(): Boolean
@DoNotStrip public fun useStateAlignmentMechanism(): Boolean
@DoNotStrip public fun useTurboModuleInterop(): Boolean
}
@@ -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<<0a159023455a26eb42e1173e533f3f3b>>
* @generated SignedSource<<02df28265377b446bcb6ddd2643b0046>>
*/
/**
@@ -285,6 +285,12 @@ class ReactNativeFeatureFlagsProviderHolder
return method(javaProvider_);
}
bool useTurboModuleInterop() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useTurboModuleInterop");
return method(javaProvider_);
}
private:
jni::global_ref<jobject> javaProvider_;
};
@@ -494,6 +500,11 @@ bool JReactNativeFeatureFlagsCxxInterop::useStateAlignmentMechanism(
return ReactNativeFeatureFlags::useStateAlignmentMechanism();
}
bool JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::useTurboModuleInterop();
}
void JReactNativeFeatureFlagsCxxInterop::override(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/,
jni::alias_ref<jobject> provider) {
@@ -634,6 +645,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"useStateAlignmentMechanism",
JReactNativeFeatureFlagsCxxInterop::useStateAlignmentMechanism),
makeNativeMethod(
"useTurboModuleInterop",
JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop),
});
}
@@ -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<<f819ca47f2da8ceee1467a282348dcd2>>
* @generated SignedSource<<e9d72b33215acf70efc41ac712a60a8c>>
*/
/**
@@ -153,6 +153,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool useStateAlignmentMechanism(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
static bool useTurboModuleInterop(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
static void override(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>,
jni::alias_ref<jobject> provider);
@@ -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<<68c3ef116de269b9f7c0e6eabe738cbd>>
* @generated SignedSource<<fd41cef602485dd86d77f4a6a56e1ba2>>
*/
/**
@@ -185,6 +185,10 @@ bool ReactNativeFeatureFlags::useStateAlignmentMechanism() {
return getAccessor().useStateAlignmentMechanism();
}
bool ReactNativeFeatureFlags::useTurboModuleInterop() {
return getAccessor().useTurboModuleInterop();
}
void ReactNativeFeatureFlags::override(
std::unique_ptr<ReactNativeFeatureFlagsProvider> provider) {
getAccessor().override(std::move(provider));
@@ -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<<df0acea0df716f125fa37bb166464a51>>
* @generated SignedSource<<3776d4da056a1745d14b7f66962380d4>>
*/
/**
@@ -242,6 +242,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool useStateAlignmentMechanism();
/**
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
*/
RN_EXPORT static bool useTurboModuleInterop();
/**
* Overrides the feature flags with the ones provided by the given provider
* (generally one that extends `ReactNativeFeatureFlagsDefaults`).
@@ -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<<0700f7b4c74e1b761c6f4a17d49d00ef>>
* @generated SignedSource<<1af5fb4f769fc2a79968dcdddb748559>>
*/
/**
@@ -767,6 +767,24 @@ bool ReactNativeFeatureFlagsAccessor::useStateAlignmentMechanism() {
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::useTurboModuleInterop() {
auto flagValue = useTurboModuleInterop_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(41, "useTurboModuleInterop");
flagValue = currentProvider_->useTurboModuleInterop();
useTurboModuleInterop_ = flagValue;
}
return flagValue.value();
}
void ReactNativeFeatureFlagsAccessor::override(
std::unique_ptr<ReactNativeFeatureFlagsProvider> provider) {
if (wasOverridden_) {
@@ -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<<292c8d1f77702728dd6916350038b34b>>
* @generated SignedSource<<416abde5c71ed1f507a466f87a353240>>
*/
/**
@@ -72,6 +72,7 @@ class ReactNativeFeatureFlagsAccessor {
bool useRuntimeShadowNodeReferenceUpdate();
bool useRuntimeShadowNodeReferenceUpdateOnLayout();
bool useStateAlignmentMechanism();
bool useTurboModuleInterop();
void override(std::unique_ptr<ReactNativeFeatureFlagsProvider> provider);
@@ -82,7 +83,7 @@ class ReactNativeFeatureFlagsAccessor {
std::unique_ptr<ReactNativeFeatureFlagsProvider> currentProvider_;
bool wasOverridden_;
std::array<std::atomic<const char*>, 41> accessedFeatureFlags_;
std::array<std::atomic<const char*>, 42> accessedFeatureFlags_;
std::atomic<std::optional<bool>> commonTestFlag_;
std::atomic<std::optional<bool>> allowCollapsableChildren_;
@@ -125,6 +126,7 @@ class ReactNativeFeatureFlagsAccessor {
std::atomic<std::optional<bool>> useRuntimeShadowNodeReferenceUpdate_;
std::atomic<std::optional<bool>> useRuntimeShadowNodeReferenceUpdateOnLayout_;
std::atomic<std::optional<bool>> useStateAlignmentMechanism_;
std::atomic<std::optional<bool>> useTurboModuleInterop_;
};
} // namespace facebook::react
@@ -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<<7f424c2da628f8b4e39053272056de77>>
* @generated SignedSource<<313e79efe731e50f9460af5f1640bec7>>
*/
/**
@@ -190,6 +190,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider {
bool useStateAlignmentMechanism() override {
return false;
}
bool useTurboModuleInterop() override {
return false;
}
};
} // namespace facebook::react
@@ -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<<352277af59c1c5b1f8fb69ea6c56c3d1>>
* @generated SignedSource<<28afd58334a064cf48b8a93eb9a22a33>>
*/
/**
@@ -66,6 +66,7 @@ class ReactNativeFeatureFlagsProvider {
virtual bool useRuntimeShadowNodeReferenceUpdate() = 0;
virtual bool useRuntimeShadowNodeReferenceUpdateOnLayout() = 0;
virtual bool useStateAlignmentMechanism() = 0;
virtual bool useTurboModuleInterop() = 0;
};
} // namespace facebook::react
@@ -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<<26a043285b837084016fd577370f1368>>
* @generated SignedSource<<e1e0e7bd162767d3de0a953e36e81859>>
*/
/**
@@ -242,4 +242,9 @@ bool NativeReactNativeFeatureFlags::useStateAlignmentMechanism(
return ReactNativeFeatureFlags::useStateAlignmentMechanism();
}
bool NativeReactNativeFeatureFlags::useTurboModuleInterop(
jsi::Runtime& /*runtime*/) {
return ReactNativeFeatureFlags::useTurboModuleInterop();
}
} // namespace facebook::react
@@ -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<<8d65290176c9cb340a3974d07a73fc52>>
* @generated SignedSource<<885110e15bc95d518c8afde7e67d78cb>>
*/
/**
@@ -116,6 +116,8 @@ class NativeReactNativeFeatureFlags
bool useRuntimeShadowNodeReferenceUpdateOnLayout(jsi::Runtime& runtime);
bool useStateAlignmentMechanism(jsi::Runtime& runtime);
bool useTurboModuleInterop(jsi::Runtime& runtime);
};
} // namespace facebook::react
@@ -236,6 +236,11 @@ const definitions: FeatureFlagDefinitions = {
description:
'When enabled, it uses optimised state reconciliation algorithm.',
},
useTurboModuleInterop: {
defaultValue: false,
description:
'In Bridgeless mode, should legacy NativeModules use the TurboModule system?',
},
},
jsOnly: {
@@ -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<<fac931449d06db3c8f5a239f1b26e164>>
* @generated SignedSource<<2a851d5f14ec61936d9ecb37d7f58831>>
* @flow strict-local
*/
@@ -85,6 +85,7 @@ export type ReactNativeFeatureFlags = {
useRuntimeShadowNodeReferenceUpdate: Getter<boolean>,
useRuntimeShadowNodeReferenceUpdateOnLayout: Getter<boolean>,
useStateAlignmentMechanism: Getter<boolean>,
useTurboModuleInterop: Getter<boolean>,
}
/**
@@ -311,6 +312,10 @@ export const useRuntimeShadowNodeReferenceUpdateOnLayout: Getter<boolean> = crea
* When enabled, it uses optimised state reconciliation algorithm.
*/
export const useStateAlignmentMechanism: Getter<boolean> = createNativeFlagGetter('useStateAlignmentMechanism', false);
/**
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
*/
export const useTurboModuleInterop: Getter<boolean> = createNativeFlagGetter('useTurboModuleInterop', false);
/**
* Overrides the feature flags with the provided methods.
@@ -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<<b76a5cb2735eed72575281f6e974d172>>
* @generated SignedSource<<ddb929c7c71960064d3f32badca4c99a>>
* @flow strict-local
*/
@@ -64,6 +64,7 @@ export interface Spec extends TurboModule {
+useRuntimeShadowNodeReferenceUpdate?: () => boolean;
+useRuntimeShadowNodeReferenceUpdateOnLayout?: () => boolean;
+useStateAlignmentMechanism?: () => boolean;
+useTurboModuleInterop?: () => boolean;
}
const NativeReactNativeFeatureFlags: ?Spec = TurboModuleRegistry.get<Spec>(