-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the New App template to reduce the amount of C++ code in user …
…space (#34666) Summary: Pull Request resolved: #34666 This diff updates the new app template and reduces the amount of C++ code in user space. From now on users will have to only: 1. Create a CMakeLists.txt file 2. Create an OnLoad.cpp file with the Modules/Components they want to provide. Changelog: [Android] [Changed] - Update the template to Reduce the amount of C++ code in user space for New Architecture Reviewed By: cipolleschi Differential Revision: D39381762 fbshipit-source-id: 7309b6c61ba9ddd8856cb4aaa6d923ddd816741c
- Loading branch information
1 parent
e89bd4a
commit b0aba1b
Showing
8 changed files
with
69 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
template/android/app/src/main/jni/MainApplicationModuleProvider.cpp
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
template/android/app/src/main/jni/MainApplicationModuleProvider.h
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
template/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
template/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h
This file was deleted.
Oops, something went wrong.
65 changes: 0 additions & 65 deletions
65
template/android/app/src/main/jni/MainComponentsRegistry.cpp
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
template/android/app/src/main/jni/MainComponentsRegistry.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,72 @@ | ||
#include <DefaultComponentsRegistry.h> | ||
#include <DefaultTurboModuleManagerDelegate.h> | ||
#include <fbjni/fbjni.h> | ||
#include "MainApplicationTurboModuleManagerDelegate.h" | ||
#include "MainComponentsRegistry.h" | ||
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h> | ||
#include <rncli.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
void registerComponents( | ||
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 | ||
rncli_registerProviders(registry); | ||
} | ||
|
||
std::shared_ptr<TurboModule> provideModules( | ||
const std::string &name, | ||
const JavaTurboModule::InitParams ¶ms) { | ||
// 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`): | ||
// | ||
// auto module = samplelibrary_ModuleProvider(moduleName, params); | ||
// if (module != nullptr) { | ||
// return module; | ||
// } | ||
// return rncore_ModuleProvider(moduleName, params); | ||
|
||
// By default we just use the module providers autolinked by RN CLI | ||
return rncli_ModuleProvider(name, params); | ||
} | ||
|
||
class MainApplicationNativeEntryPoint | ||
: public facebook::jni::HybridClass<MainApplicationNativeEntryPoint> { | ||
public: | ||
constexpr static auto kJavaDescriptor = | ||
"Lcom/facebook/react/defaults/DefaultNativeEntryPoint;"; | ||
|
||
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>) { | ||
DefaultTurboModuleManagerDelegate::moduleProvidersFromEntryPoint = | ||
&provideModules; | ||
DefaultComponentsRegistry::registerComponentDescriptorsFromEntryPoint = | ||
®isterComponents; | ||
return makeCxxInstance(); | ||
} | ||
|
||
static void registerNatives() { | ||
registerHybrid({ | ||
makeNativeMethod( | ||
"initHybrid", MainApplicationNativeEntryPoint::initHybrid), | ||
}); | ||
} | ||
|
||
private: | ||
friend HybridBase; | ||
using HybridBase::HybridBase; | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook | ||
|
||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { | ||
return facebook::jni::initialize(vm, [] { | ||
facebook::react::MainApplicationTurboModuleManagerDelegate:: | ||
registerNatives(); | ||
facebook::react::MainComponentsRegistry::registerNatives(); | ||
facebook::react::MainApplicationNativeEntryPoint::registerNatives(); | ||
}); | ||
} |