mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Reintroduce CoreComponentsRegistry class
Summary: This diff reintroduces the CoreComponentsRegistry class to register core components in the RN Tester app. This class was previously deleted as part of D23091020 (https://github.com/facebook/react-native/commit/7fb1afae7f4b78970463e272b7d4f3230e84887d). Different from a past approach, this diff doesn't use inheritance for Hybrid classes (which seems to bring problems in Android 4 devices) I'm planning to land this diff after I verify that D23091020 (https://github.com/facebook/react-native/commit/7fb1afae7f4b78970463e272b7d4f3230e84887d) fixed RC (maybe I will wait until sunday's cut) changelog: [internal] internal Reviewed By: fkgozali Differential Revision: D23109856 fbshipit-source-id: 5220e522e197f701c782ab5089f9f1036ec90c19
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e26dd1c35d
commit
c291265508
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
@DoNotStrip
|
||||
public class CoreComponentsRegistry {
|
||||
static {
|
||||
SoLoader.loadLibrary("fabricjni");
|
||||
}
|
||||
|
||||
@DoNotStrip private final HybridData mHybridData;
|
||||
|
||||
@DoNotStrip
|
||||
private native HybridData initHybrid(ComponentFactory componentFactory);
|
||||
|
||||
@DoNotStrip
|
||||
private CoreComponentsRegistry(ComponentFactory componentFactory) {
|
||||
mHybridData = initHybrid(componentFactory);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user