Refactor ComponentFactoryDelegate class

Summary:
This diff refactors the ComponentFactoryDelegate class. It also introduces a new class called ComponentRegistry that will be used to register components into fabric

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D22985313

fbshipit-source-id: e33a3d4fcb3a1c509b80c6ff1f43889480b1c2c3
This commit is contained in:
David Vacca
2020-08-07 19:49:19 -07:00
committed by Facebook GitHub Bot
parent 7d5383eea8
commit f441fe6d45
9 changed files with 49 additions and 22 deletions
@@ -38,7 +38,7 @@ public class Binding {
Object uiManager,
EventBeatManager eventBeatManager,
MessageQueueThread jsMessageQueueThread,
ComponentFactoryDelegate componentsRegistry,
ComponentFactory componentsRegistry,
Object reactNativeConfig);
public native void startSurface(
@@ -78,7 +78,7 @@ public class Binding {
@NonNull FabricUIManager fabricUIManager,
@NonNull EventBeatManager eventBeatManager,
@NonNull MessageQueueThread jsMessageQueueThread,
@NonNull ComponentFactoryDelegate componentFactoryDelegate,
@NonNull ComponentFactory componentFactory,
@NonNull ReactNativeConfig reactNativeConfig) {
fabricUIManager.setBinding(this);
installFabricUIManager(
@@ -86,7 +86,7 @@ public class Binding {
fabricUIManager,
eventBeatManager,
jsMessageQueueThread,
componentFactoryDelegate,
componentFactory,
reactNativeConfig);
setPixelDensity(PixelUtil.getDisplayMetricDensity());
}
@@ -12,7 +12,7 @@ import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public class ComponentFactoryDelegate {
public class ComponentFactory {
static {
FabricSoLoader.staticInit();
@@ -23,7 +23,7 @@ public class ComponentFactoryDelegate {
@DoNotStrip
private static native HybridData initHybrid();
public ComponentFactoryDelegate() {
public ComponentFactory() {
mHybridData = initHybrid();
}
}
@@ -0,0 +1,27 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.fabric;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
/**
* This class is responsible for registrering a set of RN Android view managers into a {@link
* ComponentFactory}.
*/
public class ComponentRegistry {
@DoNotStrip private final HybridData mHybridData;
@DoNotStrip
private native HybridData initHybrid(ComponentFactory componentFactory);
public ComponentRegistry(ComponentFactory componentFactory) {
mHybridData = initHybrid(componentFactory);
}
}
@@ -42,15 +42,15 @@ import com.facebook.systrace.Systrace;
public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
@NonNull private final ReactApplicationContext mReactApplicationContext;
@NonNull private final ComponentFactoryDelegate mComponentFactoryDelegate;
@NonNull private final ComponentFactory mComponentFactory;
@NonNull private final ReactNativeConfig mConfig;
public FabricJSIModuleProvider(
@NonNull ReactApplicationContext reactApplicationContext,
@NonNull ComponentFactoryDelegate componentFactoryDelegate,
@NonNull ComponentFactory componentFactory,
@NonNull ReactNativeConfig config) {
mReactApplicationContext = reactApplicationContext;
mComponentFactoryDelegate = componentFactoryDelegate;
mComponentFactory = componentFactory;
mConfig = config;
}
@@ -74,7 +74,7 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
uiManager,
eventBeatManager,
jsMessageQueueThread,
mComponentFactoryDelegate,
mComponentFactory,
mConfig);
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
return uiManager;
@@ -121,7 +121,7 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
LayoutMetricsConversions.class.getClass();
MountingManager.class.getClass();
Binding.class.getClass();
ComponentFactoryDelegate.class.getClass();
ComponentFactory.class.getClass();
FabricComponents.class.getClass();
FabricSoLoader.class.getClass();
FabricUIManager.class.getClass();
@@ -210,7 +210,7 @@ void Binding::installFabricUIManager(
jni::alias_ref<jobject> javaUIManager,
EventBeatManager *eventBeatManager,
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
ComponentFactoryDelegate *componentsRegistry,
ComponentFactory *componentsRegistry,
jni::alias_ref<jobject> reactNativeConfig) {
SystraceSection s("FabricUIManagerBinding::installFabricUIManager");
@@ -17,7 +17,7 @@
#include <react/renderer/uimanager/LayoutAnimationStatusDelegate.h>
#include <memory>
#include <mutex>
#include "ComponentFactoryDelegate.h"
#include "ComponentFactory.h"
#include "EventBeatManager.h"
#include "JBackgroundExecutor.h"
@@ -58,7 +58,7 @@ class Binding : public jni::HybridClass<Binding>,
jni::alias_ref<jobject> javaUIManager,
EventBeatManager *eventBeatManager,
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
ComponentFactoryDelegate *componentsRegistry,
ComponentFactory *componentsRegistry,
jni::alias_ref<jobject> reactNativeConfig);
void startSurface(
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
#include "ComponentFactoryDelegate.h"
#include "ComponentFactory.h"
#include <android/log.h>
#include <fbjni/fbjni.h>
#include <jsi/jsi.h>
@@ -16,14 +16,14 @@ using namespace facebook::jsi;
namespace facebook {
namespace react {
jni::local_ref<ComponentFactoryDelegate::jhybriddata>
ComponentFactoryDelegate::initHybrid(jni::alias_ref<jclass>) {
jni::local_ref<ComponentFactory::jhybriddata> ComponentFactory::initHybrid(
jni::alias_ref<jclass>) {
return makeCxxInstance();
}
void ComponentFactoryDelegate::registerNatives() {
void ComponentFactory::registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", ComponentFactoryDelegate::initHybrid),
makeNativeMethod("initHybrid", ComponentFactory::initHybrid),
});
}
@@ -22,11 +22,10 @@ namespace react {
class Instance;
class ComponentFactoryDelegate
: public jni::HybridClass<ComponentFactoryDelegate> {
class ComponentFactory : public jni::HybridClass<ComponentFactory> {
public:
constexpr static const char *const kJavaDescriptor =
"Lcom/facebook/react/fabric/ComponentFactoryDelegate;";
"Lcom/facebook/react/fabric/ComponentFactory;";
static void registerNatives();
@@ -8,6 +8,7 @@
#include <fbjni/fbjni.h>
#include "Binding.h"
#include "ComponentFactory.h"
#include "EventBeatManager.h"
#include "EventEmitterWrapper.h"
#include "StateWrapperImpl.h"
@@ -18,6 +19,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
facebook::react::EventBeatManager::registerNatives();
facebook::react::EventEmitterWrapper::registerNatives();
facebook::react::StateWrapperImpl::registerNatives();
facebook::react::ComponentFactoryDelegate::registerNatives();
facebook::react::ComponentFactory::registerNatives();
});
}