Skip to content

Commit

Permalink
Update the OnLoad.cpp to use the facebook::react namespace
Browse files Browse the repository at this point in the history
Summary:
Small follow up to my template update. Using the namespace in the OnLoad.cpp
should prevent name clashing and make it easier to read.

Changelog:
[Android] [Changed] - Update the OnLoad.cpp to use the facebook::react namespace

Reviewed By: cipolleschi

Differential Revision: D39475773

fbshipit-source-id: 9c0748d37858196d4e8ea6674d9cfd6ef4eff1cd
  • Loading branch information
cortinico authored and facebook-github-bot committed Sep 14, 2022
1 parent 59dc7f1 commit aba82a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
22 changes: 14 additions & 8 deletions packages/rn-tester/android/app/src/main/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
#include <react/renderer/components/AppSpecs/ComponentDescriptors.h>
#include <rncore.h>

namespace facebook {
namespace react {

void registerComponents(
std::shared_ptr<facebook::react::ComponentDescriptorProviderRegistry const>
registry) {
registry->add(facebook::react::concreteComponentDescriptorProvider<
facebook::react::RNTMyNativeViewComponentDescriptor>());
std::shared_ptr<ComponentDescriptorProviderRegistry const> registry) {
registry->add(concreteComponentDescriptorProvider<
RNTMyNativeViewComponentDescriptor>());
}

std::shared_ptr<facebook::react::TurboModule> provideModules(
std::shared_ptr<TurboModule> provideModules(
const std::string &name,
const facebook::react::JavaTurboModule::InitParams &params) {
const JavaTurboModule::InitParams &params) {
auto module = AppSpecs_ModuleProvider(name, params);
if (module != nullptr) {
return module;
Expand All @@ -35,11 +37,15 @@ std::shared_ptr<facebook::react::TurboModule> provideModules(
return rncore_ModuleProvider(name, params);
}

} // namespace react
} // namespace facebook

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
return facebook::jni::initialize(vm, [] {
facebook::react::DefaultTurboModuleManagerDelegate::
moduleProvidersFromEntryPoint = &provideModules;
moduleProvidersFromEntryPoint = &facebook::react::provideModules;
facebook::react::DefaultComponentsRegistry::
registerComponentDescriptorsFromEntryPoint = &registerComponents;
registerComponentDescriptorsFromEntryPoint =
&facebook::react::registerComponents;
});
}
22 changes: 14 additions & 8 deletions template/android/app/src/main/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <rncli.h>

namespace facebook {
namespace react {

void registerComponents(
std::shared_ptr<facebook::react::ComponentDescriptorProviderRegistry const>
registry) {
std::shared_ptr<ComponentDescriptorProviderRegistry const> registry) {
// Custom Fabric Components go here. You can register custom
// components coming from your App or from 3rd party libraries here.
//
// providerRegistry->add(concreteComponentDescriptorProvider<
// AocViewerComponentDescriptor>());

// By default we just use the components autolinked by RN CLI
facebook::react::rncli_registerProviders(registry);
rncli_registerProviders(registry);
}

std::shared_ptr<facebook::react::TurboModule> provideModules(
std::shared_ptr<TurboModule> provideModules(
const std::string &name,
const facebook::react::JavaTurboModule::InitParams &params) {
const JavaTurboModule::InitParams &params) {
// Here you can provide your own module provider for TurboModules coming from
// either your application or from external libraries. The approach to follow
// is similar to the following (for a library called `samplelibrary`):
Expand All @@ -31,14 +33,18 @@ std::shared_ptr<facebook::react::TurboModule> provideModules(
// return rncore_ModuleProvider(moduleName, params);

// By default we just use the module providers autolinked by RN CLI
return facebook::react::rncli_ModuleProvider(name, params);
return rncli_ModuleProvider(name, params);
}

} // namespace react
} // namespace facebook

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
return facebook::jni::initialize(vm, [] {
facebook::react::DefaultTurboModuleManagerDelegate::
moduleProvidersFromEntryPoint = &provideModules;
moduleProvidersFromEntryPoint = &facebook::react::provideModules;
facebook::react::DefaultComponentsRegistry::
registerComponentDescriptorsFromEntryPoint = &registerComponents;
registerComponentDescriptorsFromEntryPoint =
&facebook::react::registerComponents;
});
}

0 comments on commit aba82a5

Please sign in to comment.