From 44eab011ef5c52c5bfaf79c8fd5caf09295de6d4 Mon Sep 17 00:00:00 2001 From: Illia Gerasymov Date: Sun, 18 Oct 2026 16:09:51 +0300 Subject: [PATCH] Return only view manager names from bridgeless UIManager.getConstants() In bridgeless mode, UIManager.getConstants() builds the constants of all eager view managers. This step uses reflection on each view manager. BridgelessUIManager calls getConstants() when it loads. Thus, each cold start does this work before the first screen. This change makes getConstants() return the same data as the old architecture with lazy view managers: the UIManager constants and the names of all view managers. When JS needs the constants of one view manager, it calls getConstantsForViewManager(). This function finds eager and lazy view managers. The JS code does not change. BridgelessUIManager makes a lazy getter for each name. getViewManagerConfig() uses getConstantsForViewManager(). getNativeComponentAttributes() uses getDefaultEventTypes(). --- .../facebook/react/runtime/ReactInstance.kt | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt index de3416e75f46..6afdb449d6f9 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt @@ -223,12 +223,6 @@ internal class ReactInstance( UIConstantsProviderBinding.install( // Use unbuffered RuntimeExecutor to install binding unbufferedRuntimeExecutor, - // Here we are construncting the return value for UManager.getConstants call. - // The old architectre relied on the constatnts struct to contain: - // 1. Eagerly loaded view configs for all native components. - // 2. genericBubblingEventTypes. - // 3. genericDirectEventTypes. - // We want to match this beahavior. { Arguments.makeNativeMap(UIManagerModuleConstantsHelper.defaultExportableEventTypes) }, ConstantsForViewManagerProvider { viewManagerName: String -> val viewManager = @@ -236,18 +230,8 @@ internal class ReactInstance( ?: return@ConstantsForViewManagerProvider null getConstantsForViewManager(viewManager, customDirectEvents) }, - { - val viewManagers: List> = - ArrayList(viewManagerResolver.eagerViewManagerMap.values) - val constants = createConstants(viewManagers, customDirectEvents) - - val lazyViewManagers = viewManagerResolver.lazyViewManagerNames - if (!lazyViewManagers.isEmpty()) { - constants["ViewManagerNames"] = ArrayList(lazyViewManagers) - constants["LazyViewManagersEnabled"] = true - } - Arguments.makeNativeMap(constants) - }, + // Names only: each view config is built on first use. + { Arguments.makeNativeMap(createConstants(viewManagerResolver)) }, ) } @@ -584,20 +568,13 @@ internal class ReactInstance( SoLoader.loadLibrary("rninstance") } - private fun createConstants( - viewManagers: List>, - customDirectEvents: MutableMap?, - ): MutableMap { + private fun createConstants(viewManagerResolver: ViewManagerResolver): Map { ReactMarker.logMarker(ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_CONSTANTS_START) SystraceMessage.beginSection(Systrace.TRACE_TAG_REACT, "CreateUIManagerConstants") - .arg("Lazy", false) + .arg("Lazy", true) .flush() try { - return UIManagerModuleConstantsHelper.createConstants( - viewManagers, - null, - customDirectEvents, - ) + return UIManagerModuleConstantsHelper.createConstants(viewManagerResolver) } finally { Systrace.endSection(Systrace.TRACE_TAG_REACT) ReactMarker.logMarker(ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_CONSTANTS_END)