Register C++ ViewManagers in React Native Renderer

Summary:
This diff integrates the registration of C++ component into React Native Android

changelog: [internal] internal

Reviewed By: sammy-SC

Differential Revision: D38725769

fbshipit-source-id: 33eb9ebb93983c4038529748758eac3e43eec3e5
This commit is contained in:
David Vacca
2022-09-15 09:48:25 -07:00
committed by Facebook GitHub Bot
parent a2d2a1df90
commit 0519dfeeaf
4 changed files with 56 additions and 5 deletions
@@ -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());
}
@@ -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<UIManager> {
@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> {
uiManager,
eventBeatManager,
mComponentFactory,
mConfig);
mConfig,
mCppComponentRegistry);
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
@@ -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<jobject> javaUIManager,
EventBeatManager *eventBeatManager,
ComponentFactory *componentsRegistry,
jni::alias_ref<jobject> reactNativeConfig) {
jni::alias_ref<jobject> reactNativeConfig,
CppComponentRegistry *cppComponentRegistry) {
SystraceSection s("FabricUIManagerBinding::installFabricUIManager");
std::shared_ptr<const ReactNativeConfig> config =
@@ -491,6 +493,7 @@ void Binding::uninstallFabricUIManager() {
scheduler_ = nullptr;
mountingManager_ = nullptr;
reactNativeConfig_ = nullptr;
sharedCppComponentRegistry_ = nullptr;
}
std::shared_ptr<FabricMountingManager> 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,
@@ -7,6 +7,7 @@
#pragma once
#include "CppComponentRegistry.h"
#include "FabricMountingManager.h"
#include <memory>
@@ -65,7 +66,8 @@ class Binding : public jni::HybridClass<Binding>,
jni::alias_ref<jobject> javaUIManager,
EventBeatManager *eventBeatManager,
ComponentFactory *componentsRegistry,
jni::alias_ref<jobject> reactNativeConfig);
jni::alias_ref<jobject> reactNativeConfig,
CppComponentRegistry *cppComponentRegistry);
void startSurface(
jint surfaceId,
@@ -150,6 +152,8 @@ class Binding : public jni::HybridClass<Binding>,
float pointScaleFactor_ = 1;
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_{nullptr};
std::shared_ptr<const facebook::react::CppComponentRegistry>
sharedCppComponentRegistry_{nullptr};
bool disablePreallocateViews_{false};
bool enableFabricLogs_{false};
bool disableRevisionCheckForPreallocation_{false};