Bez popisu

MainComponentsRegistry.cpp 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "MainComponentsRegistry.h"
  2. #include <CoreComponentsRegistry.h>
  3. #include <fbjni/fbjni.h>
  4. #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
  5. #include <react/renderer/components/rncore/ComponentDescriptors.h>
  6. #include <rncli.h>
  7. namespace facebook {
  8. namespace react {
  9. MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {}
  10. std::shared_ptr<ComponentDescriptorProviderRegistry const>
  11. MainComponentsRegistry::sharedProviderRegistry() {
  12. auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
  13. // Autolinked providers registered by RN CLI
  14. rncli_registerProviders(providerRegistry);
  15. // Custom Fabric Components go here. You can register custom
  16. // components coming from your App or from 3rd party libraries here.
  17. //
  18. // providerRegistry->add(concreteComponentDescriptorProvider<
  19. // AocViewerComponentDescriptor>());
  20. return providerRegistry;
  21. }
  22. jni::local_ref<MainComponentsRegistry::jhybriddata>
  23. MainComponentsRegistry::initHybrid(
  24. jni::alias_ref<jclass>,
  25. ComponentFactory *delegate) {
  26. auto instance = makeCxxInstance(delegate);
  27. auto buildRegistryFunction =
  28. [](EventDispatcher::Weak const &eventDispatcher,
  29. ContextContainer::Shared const &contextContainer)
  30. -> ComponentDescriptorRegistry::Shared {
  31. auto registry = MainComponentsRegistry::sharedProviderRegistry()
  32. ->createComponentDescriptorRegistry(
  33. {eventDispatcher, contextContainer});
  34. auto mutableRegistry =
  35. std::const_pointer_cast<ComponentDescriptorRegistry>(registry);
  36. mutableRegistry->setFallbackComponentDescriptor(
  37. std::make_shared<UnimplementedNativeViewComponentDescriptor>(
  38. ComponentDescriptorParameters{
  39. eventDispatcher, contextContainer, nullptr}));
  40. return registry;
  41. };
  42. delegate->buildRegistryFunction = buildRegistryFunction;
  43. return instance;
  44. }
  45. void MainComponentsRegistry::registerNatives() {
  46. registerHybrid({
  47. makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid),
  48. });
  49. }
  50. } // namespace react
  51. } // namespace facebook