diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.java index a46b65c27ce..182281d168b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.java @@ -42,7 +42,8 @@ public class Binding { Object uiManager, EventBeatManager eventBeatManager, ComponentFactory componentsRegistry, - Object reactNativeConfig); + Object reactNativeConfig, + CppComponentRegistry cppComponentRegistry); public native void startSurface( int surfaceId, @NonNull String moduleName, @NonNull NativeMap initialProps); @@ -89,6 +90,24 @@ public class Binding { @NonNull EventBeatManager eventBeatManager, @NonNull ComponentFactory componentFactory, @NonNull ReactNativeConfig reactNativeConfig) { + register( + runtimeExecutor, + runtimeScheduler, + fabricUIManager, + eventBeatManager, + componentFactory, + reactNativeConfig, + null); + } + + public void register( + @NonNull RuntimeExecutor runtimeExecutor, + @Nullable RuntimeScheduler runtimeScheduler, + @NonNull FabricUIManager fabricUIManager, + @NonNull EventBeatManager eventBeatManager, + @NonNull ComponentFactory componentFactory, + @NonNull ReactNativeConfig reactNativeConfig, + @Nullable CppComponentRegistry cppComponentRegistry) { fabricUIManager.setBinding(this); installFabricUIManager( runtimeExecutor, @@ -96,7 +115,8 @@ public class Binding { fabricUIManager, eventBeatManager, componentFactory, - reactNativeConfig); + reactNativeConfig, + cppComponentRegistry); setPixelDensity(PixelUtil.getDisplayMetricDensity()); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java index bbb76d993b2..afbc53839c7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java @@ -8,6 +8,7 @@ package com.facebook.react.fabric; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.facebook.react.bridge.JSIModuleProvider; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.UIManager; @@ -23,16 +24,27 @@ public class FabricJSIModuleProvider implements JSIModuleProvider { @NonNull private final ComponentFactory mComponentFactory; @NonNull private final ReactNativeConfig mConfig; @NonNull private final ViewManagerRegistry mViewManagerRegistry; + @Nullable private final CppComponentRegistry mCppComponentRegistry; public FabricJSIModuleProvider( @NonNull ReactApplicationContext reactApplicationContext, @NonNull ComponentFactory componentFactory, @NonNull ReactNativeConfig config, @NonNull ViewManagerRegistry viewManagerRegistry) { + this(reactApplicationContext, componentFactory, config, viewManagerRegistry, null); + } + + public FabricJSIModuleProvider( + @NonNull ReactApplicationContext reactApplicationContext, + @NonNull ComponentFactory componentFactory, + @NonNull ReactNativeConfig config, + @NonNull ViewManagerRegistry viewManagerRegistry, + @Nullable CppComponentRegistry cppComponentRegistry) { mReactApplicationContext = reactApplicationContext; mComponentFactory = componentFactory; mConfig = config; mViewManagerRegistry = viewManagerRegistry; + mCppComponentRegistry = cppComponentRegistry; } @Override @@ -55,7 +67,8 @@ public class FabricJSIModuleProvider implements JSIModuleProvider { uiManager, eventBeatManager, mComponentFactory, - mConfig); + mConfig, + mCppComponentRegistry); Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); diff --git a/ReactAndroid/src/main/jni/react/fabric/Binding.cpp b/ReactAndroid/src/main/jni/react/fabric/Binding.cpp index 827ce224549..a419fcefc8f 100644 --- a/ReactAndroid/src/main/jni/react/fabric/Binding.cpp +++ b/ReactAndroid/src/main/jni/react/fabric/Binding.cpp @@ -8,6 +8,7 @@ #include "Binding.h" #include "AsyncEventBeat.h" +#include "CppComponentRegistry.h" #include "EventEmitterWrapper.h" #include "JBackgroundExecutor.h" #include "ReactNativeConfigHolder.h" @@ -360,7 +361,8 @@ void Binding::installFabricUIManager( jni::alias_ref javaUIManager, EventBeatManager *eventBeatManager, ComponentFactory *componentsRegistry, - jni::alias_ref reactNativeConfig) { + jni::alias_ref reactNativeConfig, + CppComponentRegistry *cppComponentRegistry) { SystraceSection s("FabricUIManagerBinding::installFabricUIManager"); std::shared_ptr config = @@ -491,6 +493,7 @@ void Binding::uninstallFabricUIManager() { scheduler_ = nullptr; mountingManager_ = nullptr; reactNativeConfig_ = nullptr; + sharedCppComponentRegistry_ = nullptr; } std::shared_ptr Binding::verifyMountingManager( @@ -561,6 +564,17 @@ void Binding::schedulerDidCloneShadowNode( void Binding::preallocateView( SurfaceId surfaceId, ShadowNode const &shadowNode) { + auto name = std::string(shadowNode.getComponentName()); + + // Disable preallocation in java for C++ view managers + // RootComponents that are implmented as C++ view managers are still + // preallocated (this could be avoided by using Portals) + if (sharedCppComponentRegistry_ && sharedCppComponentRegistry_.get() && + sharedCppComponentRegistry_->containsComponentManager(name) && + !sharedCppComponentRegistry_->isRootComponent(name)) { + return; + } + auto shadowView = ShadowView(shadowNode); auto preallocationFunction = [this, surfaceId, diff --git a/ReactAndroid/src/main/jni/react/fabric/Binding.h b/ReactAndroid/src/main/jni/react/fabric/Binding.h index ddfe7a5018b..bf9d5c34e6b 100644 --- a/ReactAndroid/src/main/jni/react/fabric/Binding.h +++ b/ReactAndroid/src/main/jni/react/fabric/Binding.h @@ -7,6 +7,7 @@ #pragma once +#include "CppComponentRegistry.h" #include "FabricMountingManager.h" #include @@ -65,7 +66,8 @@ class Binding : public jni::HybridClass, jni::alias_ref javaUIManager, EventBeatManager *eventBeatManager, ComponentFactory *componentsRegistry, - jni::alias_ref reactNativeConfig); + jni::alias_ref reactNativeConfig, + CppComponentRegistry *cppComponentRegistry); void startSurface( jint surfaceId, @@ -150,6 +152,8 @@ class Binding : public jni::HybridClass, float pointScaleFactor_ = 1; std::shared_ptr reactNativeConfig_{nullptr}; + std::shared_ptr + sharedCppComponentRegistry_{nullptr}; bool disablePreallocateViews_{false}; bool enableFabricLogs_{false}; bool disableRevisionCheckForPreallocation_{false};