Create CoreComponentsRegistry

Summary:
This diff introduces the class CoreComponentsRegistry that is responsible of registering core components in fabric.
This is required to make RN Tester to work in Fabric, in the future we'll extract this registry into another module (once we figure it out what's the best way to do this)

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D22991876

fbshipit-source-id: 15e85e15aac5dd981161d9eae35eb2cee4fa66b6
This commit is contained in:
David Vacca
2020-08-07 19:45:52 -07:00
committed by Facebook GitHub Bot
parent f441fe6d45
commit bb15437db9
4 changed files with 135 additions and 0 deletions
@@ -0,0 +1,26 @@
/*
* 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.proguard.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader;
@DoNotStrip
public class CoreComponentsRegistry extends ComponentRegistry {
static {
SoLoader.loadLibrary("fabricjni");
}
private CoreComponentsRegistry(ComponentFactory componentFactory) {
super(componentFactory);
}
public static CoreComponentsRegistry register(ComponentFactory componentFactory) {
return new CoreComponentsRegistry(componentFactory);
}
}
@@ -0,0 +1,65 @@
/*
* 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.
*/
#include "CoreComponentsRegistry.h"
#include <android/log.h>
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
#include <react/renderer/components/view/ViewComponentDescriptor.h>
namespace facebook {
namespace react {
CoreComponentsRegistry::CoreComponentsRegistry(ComponentFactory *delegate)
: delegate_(delegate) {}
std::shared_ptr<ComponentDescriptorProviderRegistry const>
CoreComponentsRegistry::sharedProviderRegistry() {
static auto providerRegistry =
[]() -> std::shared_ptr<ComponentDescriptorProviderRegistry> {
auto providerRegistry =
std::make_shared<ComponentDescriptorProviderRegistry>();
providerRegistry->add(
concreteComponentDescriptorProvider<ViewComponentDescriptor>());
return providerRegistry;
}();
return providerRegistry;
}
jni::local_ref<CoreComponentsRegistry::jhybriddata>
CoreComponentsRegistry::initHybrid(
jni::alias_ref<jclass>,
ComponentFactory *delegate) {
auto instance = makeCxxInstance(delegate);
auto buildRegistryFunction =
[](EventDispatcher::Weak const &eventDispatcher,
ContextContainer::Shared const &contextContainer)
-> ComponentDescriptorRegistry::Shared {
auto registry = CoreComponentsRegistry::sharedProviderRegistry()
->createComponentDescriptorRegistry(
{eventDispatcher, contextContainer});
return registry;
};
delegate->buildRegistryFunction = buildRegistryFunction;
return instance;
}
void CoreComponentsRegistry::registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", CoreComponentsRegistry::initHybrid),
});
}
} // namespace react
} // namespace facebook
@@ -0,0 +1,42 @@
/*
* 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.
*/
#pragma once
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
#include "ComponentFactory.h"
namespace facebook {
namespace react {
class CoreComponentsRegistry
: public facebook::jni::HybridClass<CoreComponentsRegistry> {
public:
constexpr static auto kJavaDescriptor =
"Lcom/facebook/react/fabric/CoreComponentsRegistry;";
static void registerNatives();
CoreComponentsRegistry(ComponentFactory *delegate);
private:
friend HybridBase;
static std::shared_ptr<ComponentDescriptorProviderRegistry const>
sharedProviderRegistry();
const ComponentFactory *delegate_;
static jni::local_ref<jhybriddata> initHybrid(
jni::alias_ref<jclass>,
ComponentFactory *delegate);
};
} // namespace react
} // namespace facebook
@@ -9,6 +9,7 @@
#include "Binding.h"
#include "ComponentFactory.h"
#include "CoreComponentsRegistry.h"
#include "EventBeatManager.h"
#include "EventEmitterWrapper.h"
#include "StateWrapperImpl.h"
@@ -20,5 +21,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
facebook::react::EventEmitterWrapper::registerNatives();
facebook::react::StateWrapperImpl::registerNatives();
facebook::react::ComponentFactory::registerNatives();
facebook::react::CoreComponentsRegistry::registerNatives();
});
}