diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-06-07 17:50:05 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-06-07 17:50:05 -0500 |
commit | 47250e7ed7d608e499ae8f3ec99494269db30292 (patch) | |
tree | af6b1bacba4b8e56149505f49a4022a92e7025aa /android/app/src/main/jni/MainComponentsRegistry.cpp | |
download | voidsky-47250e7ed7d608e499ae8f3ec99494269db30292.tar.zst |
Initial commit
Diffstat (limited to 'android/app/src/main/jni/MainComponentsRegistry.cpp')
-rw-r--r-- | android/app/src/main/jni/MainComponentsRegistry.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/android/app/src/main/jni/MainComponentsRegistry.cpp b/android/app/src/main/jni/MainComponentsRegistry.cpp new file mode 100644 index 000000000..8f7edffd6 --- /dev/null +++ b/android/app/src/main/jni/MainComponentsRegistry.cpp @@ -0,0 +1,61 @@ +#include "MainComponentsRegistry.h" + +#include <CoreComponentsRegistry.h> +#include <fbjni/fbjni.h> +#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h> +#include <react/renderer/components/rncore/ComponentDescriptors.h> + +namespace facebook { +namespace react { + +MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {} + +std::shared_ptr<ComponentDescriptorProviderRegistry const> +MainComponentsRegistry::sharedProviderRegistry() { + auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); + + // Custom Fabric Components go here. You can register custom + // components coming from your App or from 3rd party libraries here. + // + // providerRegistry->add(concreteComponentDescriptorProvider< + // AocViewerComponentDescriptor>()); + return providerRegistry; +} + +jni::local_ref<MainComponentsRegistry::jhybriddata> +MainComponentsRegistry::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 = MainComponentsRegistry::sharedProviderRegistry() + ->createComponentDescriptorRegistry( + {eventDispatcher, contextContainer}); + + auto mutableRegistry = + std::const_pointer_cast<ComponentDescriptorRegistry>(registry); + + mutableRegistry->setFallbackComponentDescriptor( + std::make_shared<UnimplementedNativeViewComponentDescriptor>( + ComponentDescriptorParameters{ + eventDispatcher, contextContainer, nullptr})); + + return registry; + }; + + delegate->buildRegistryFunction = buildRegistryFunction; + return instance; +} + +void MainComponentsRegistry::registerNatives() { + registerHybrid({ + makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid), + }); +} + +} // namespace react +} // namespace facebook |