Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ abstract class GenerateEntryPointTask : DefaultTask() {
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger;
import com.facebook.react.uimanager.UIManagerConstantsCache;
import com.facebook.react.views.view.WindowUtilKt;
import com.facebook.react.soloader.OpenSourceMergedSoMapping;
import com.facebook.soloader.SoLoader;
Expand All @@ -95,6 +96,7 @@ abstract class GenerateEntryPointTask : DefaultTask() {
if ({{packageName}}.BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
DefaultNewArchitectureEntryPoint.load();
UIManagerConstantsCache.maybePreload(context);
}
if ({{packageName}}.BuildConfig.IS_EDGE_TO_EDGE_ENABLED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class GenerateEntryPointTaskTest {

import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger;
import com.facebook.react.uimanager.UIManagerConstantsCache;
import com.facebook.react.views.view.WindowUtilKt;
import com.facebook.react.soloader.OpenSourceMergedSoMapping;
import com.facebook.soloader.SoLoader;
Expand All @@ -78,6 +79,7 @@ class GenerateEntryPointTaskTest {

if (com.facebook.react.BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
DefaultNewArchitectureEntryPoint.load();
UIManagerConstantsCache.maybePreload(context);
}

if (com.facebook.react.BuildConfig.IS_EDGE_TO_EDGE_ENABLED) {
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<<5144fb0350b71394206d614c68ef87f0>>
* @generated SignedSource<<5765eb9864a1280e5c8706a8cfb22e5b>>
*/

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

/**
* When enabled, bridgeless mode skips the native persisted UIManager constants cache and always computes constants on demand.
*/
@JvmStatic
public fun disableNativeUIManagerConstantsCacheInBridgelessMode(): Boolean = accessor.disableNativeUIManagerConstantsCacheInBridgelessMode()

/**
* When enabled, ReactScrollView will extend NestedScrollView instead of ScrollView on Android for improved nested scrolling support.
*/
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<<d284f066f036908977797a381a044dfa>>
* @generated SignedSource<<06438b87ea376f37c31a272e8dc04597>>
*/

/**
Expand Down Expand Up @@ -101,6 +101,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var useAlwaysAvailableJSErrorHandlingCache: Boolean? = null
private var useFabricInteropCache: Boolean? = null
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
private var disableNativeUIManagerConstantsCacheInBridgelessModeCache: Boolean? = null
private var useNestedScrollViewAndroidCache: Boolean? = null
private var useSharedAnimatedBackendCache: Boolean? = null
private var useTraitHiddenOnAndroidCache: Boolean? = null
Expand Down Expand Up @@ -840,6 +841,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

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

override fun useNestedScrollViewAndroid(): Boolean {
var cached = useNestedScrollViewAndroidCache
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<<de1c66a540520cd88c4d358ba30f2c6d>>
* @generated SignedSource<<1e88e791ede99c1a251a37405bafdbef>>
*/

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

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

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

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

@DoNotStrip @JvmStatic public external fun useSharedAnimatedBackend(): 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<<ab3b1d2277b8cc9db1708ef94515fb35>>
* @generated SignedSource<<c84cfe57aee20fe67cd4827cda00876c>>
*/

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

override fun useNativeViewConfigsInBridgelessMode(): Boolean = false

override fun disableNativeUIManagerConstantsCacheInBridgelessMode(): Boolean = true

override fun useNestedScrollViewAndroid(): Boolean = false

override fun useSharedAnimatedBackend(): 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<<7b87f5541ecf881d8ce51c5edd5b99b0>>
* @generated SignedSource<<cfdb8838fe998e0f657de180f3dc271c>>
*/

/**
Expand Down Expand Up @@ -105,6 +105,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var useAlwaysAvailableJSErrorHandlingCache: Boolean? = null
private var useFabricInteropCache: Boolean? = null
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
private var disableNativeUIManagerConstantsCacheInBridgelessModeCache: Boolean? = null
private var useNestedScrollViewAndroidCache: Boolean? = null
private var useSharedAnimatedBackendCache: Boolean? = null
private var useTraitHiddenOnAndroidCache: Boolean? = null
Expand Down Expand Up @@ -925,6 +926,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

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

override fun useNestedScrollViewAndroid(): Boolean {
var cached = useNestedScrollViewAndroidCache
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<<f34b257861830bae7012fc5201904831>>
* @generated SignedSource<<bcd1a8c1320ffe6a5e5b09edcc10652d>>
*/

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

@DoNotStrip public fun useNativeViewConfigsInBridgelessMode(): Boolean

@DoNotStrip public fun disableNativeUIManagerConstantsCacheInBridgelessMode(): Boolean

@DoNotStrip public fun useNestedScrollViewAndroid(): Boolean

@DoNotStrip public fun useSharedAnimatedBackend(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import com.facebook.react.uimanager.DisplayMetricsHolder
import com.facebook.react.uimanager.IllegalViewOperationException
import com.facebook.react.uimanager.UIConstantsProviderBinding
import com.facebook.react.uimanager.UIConstantsProviderBinding.ConstantsForViewManagerProvider
import com.facebook.react.uimanager.UIManagerConstantsCache
import com.facebook.react.uimanager.UIManagerModuleConstantsHelper
import com.facebook.react.uimanager.ViewManager
import com.facebook.react.uimanager.ViewManagerRegistry
Expand Down Expand Up @@ -219,6 +220,11 @@ internal class ReactInstance(
// initialized.
// This happens inside getTurboModuleManagerDelegate getter.
if (ReactNativeFeatureFlags.useNativeViewConfigsInBridgelessMode()) {
val shouldUseNativeUIManagerConstantsCache =
!ReactNativeFeatureFlags.disableNativeUIManagerConstantsCacheInBridgelessMode()
if (shouldUseNativeUIManagerConstantsCache) {
UIManagerConstantsCache.maybePreload(context)
}
val customDirectEvents: MutableMap<String, Any> = HashMap()

UIConstantsProviderBinding.install(
Expand All @@ -232,12 +238,43 @@ internal class ReactInstance(
// We want to match this beahavior.
{ Arguments.makeNativeMap(UIManagerModuleConstantsHelper.defaultExportableEventTypes) },
ConstantsForViewManagerProvider { viewManagerName: String ->
if (shouldUseNativeUIManagerConstantsCache) {
UIManagerConstantsCache
.getCachedConstantsForViewManager(
context,
viewManagerName,
customDirectEvents,
context.sourceURL,
)
?.let { cachedConstants -> return@ConstantsForViewManagerProvider cachedConstants }
}

val viewManager =
viewManagerResolver.getViewManager(viewManagerName)
?: return@ConstantsForViewManagerProvider null
getConstantsForViewManager(viewManager, customDirectEvents)
val viewManagerConstants =
createConstantsForViewManagerMap(viewManager, customDirectEvents)
if (shouldUseNativeUIManagerConstantsCache) {
UIManagerConstantsCache.saveConstantsForViewManager(
context,
viewManagerName,
viewManagerConstants,
customDirectEvents,
context.sourceURL,
)
}
Arguments.makeNativeMap(viewManagerConstants)
},
{
if (shouldUseNativeUIManagerConstantsCache) {
UIManagerConstantsCache
.getCachedConstants(
context,
customDirectEvents,
context.sourceURL,
)
?.let { cachedConstants -> return@install cachedConstants }
}
val viewManagers: List<ViewManager<*, *>> =
ArrayList(viewManagerResolver.eagerViewManagerMap.values)
val constants = createConstants(viewManagers, customDirectEvents)
Expand All @@ -247,6 +284,14 @@ internal class ReactInstance(
constants["ViewManagerNames"] = ArrayList(lazyViewManagers)
constants["LazyViewManagersEnabled"] = true
}
if (shouldUseNativeUIManagerConstantsCache) {
UIManagerConstantsCache.saveConstants(
context,
constants,
customDirectEvents,
context.sourceURL,
)
}
Arguments.makeNativeMap(constants)
},
)
Expand Down Expand Up @@ -616,6 +661,14 @@ internal class ReactInstance(
viewManager: ViewManager<*, *>,
customDirectEvents: MutableMap<String, Any>,
): NativeMap {
val viewManagerConstants = createConstantsForViewManagerMap(viewManager, customDirectEvents)
return Arguments.makeNativeMap(viewManagerConstants)
}

private fun createConstantsForViewManagerMap(
viewManager: ViewManager<*, *>,
customDirectEvents: MutableMap<String, Any>,
): Map<String, Any?> {
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT,
"ReactInstance.getConstantsForViewManager",
Expand All @@ -624,15 +677,13 @@ internal class ReactInstance(
.arg("Lazy", true)
.flush()
try {
val viewManagerConstants: Map<String, Any> =
UIManagerModuleConstantsHelper.createConstantsForViewManager(
return UIManagerModuleConstantsHelper.createConstantsForViewManager(
viewManager,
null,
null,
null,
customDirectEvents,
)
return Arguments.makeNativeMap(viewManagerConstants)
} finally {
SystraceMessage.endSection(Systrace.TRACE_TAG_REACT).flush()
}
Expand Down
Loading