1 // Copyright 2018-present 650 Industries. All rights reserved. 2 3 #include "FabricComponentsRegistry.h" 4 5 #include <react/renderer/componentregistry/ComponentDescriptorProvider.h> 6 #include <CoreComponentsRegistry.h> 7 8 #include "ExpoViewComponentDescriptor.h" 9 10 namespace jni = facebook::jni; 11 namespace react = facebook::react; 12 13 namespace expo { 14 15 // static registerNatives()16void FabricComponentsRegistry::registerNatives() { 17 registerHybrid({ 18 makeNativeMethod("initHybrid", FabricComponentsRegistry::initHybrid), 19 makeNativeMethod("registerComponentsRegistry", FabricComponentsRegistry::registerComponentsRegistry), 20 }); 21 } 22 23 // static 24 jni::local_ref<FabricComponentsRegistry::jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis)25FabricComponentsRegistry::initHybrid(jni::alias_ref<jhybridobject> jThis) { 26 return makeCxxInstance(); 27 } 28 registerComponentsRegistry(jni::alias_ref<jni::JArrayClass<jni::JString>> componentNames)29void FabricComponentsRegistry::registerComponentsRegistry( 30 jni::alias_ref<jni::JArrayClass<jni::JString>> componentNames) { 31 // Inject the component to the CoreComponentsRegistry because we don't want to touch the MainApplicationReactNativeHost 32 auto providerRegistry = react::CoreComponentsRegistry::sharedProviderRegistry(); 33 34 size_t size = componentNames->size(); 35 for (size_t i = 0; i < size; ++i) { 36 auto flavor = std::make_shared<std::string const>(componentNames->getElement(i)->toStdString()); 37 auto componentName = react::ComponentName{flavor->c_str()}; 38 providerRegistry->add(react::ComponentDescriptorProvider { 39 reinterpret_cast<react::ComponentHandle>(componentName), 40 componentName, 41 flavor, 42 &facebook::react::concreteComponentDescriptorConstructor<expo::ExpoViewComponentDescriptor> 43 }); 44 } 45 } 46 47 } // namespace expo 48