-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TurboModule] Add the C++ implementation for MainApplicationTurboModu…
…leManagerDelegate
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
android/app/src/main/jni/MainApplicationModuleProvider.cpp
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "MainApplicationModuleProvider.h" | ||
|
||
#include <rncore.h> | ||
#include <answersolver.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
std::shared_ptr<TurboModule> MainApplicationModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams ¶ms) { | ||
auto module = answersolver_ModuleProvider(moduleName, params); | ||
if (module != nullptr) { | ||
return module; | ||
} | ||
|
||
return rncore_ModuleProvider(moduleName, params); | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include <ReactCommon/JavaTurboModule.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
std::shared_ptr<TurboModule> MainApplicationModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams ¶ms); | ||
|
||
} // namespace react | ||
} // namespace facebook |
27 changes: 27 additions & 0 deletions
27
android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "MainApplicationTurboModuleManagerDelegate.h" | ||
#include "MainApplicationModuleProvider.h" | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
jni::local_ref<MainApplicationTurboModuleManagerDelegate::jhybriddata> MainApplicationTurboModuleManagerDelegate::initHybrid(jni::alias_ref<jhybridobject>) { | ||
return makeCxxInstance(); | ||
} | ||
|
||
void MainApplicationTurboModuleManagerDelegate::registerNatives() { | ||
registerHybrid({ | ||
makeNativeMethod("initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid), | ||
}); | ||
} | ||
|
||
std::shared_ptr<TurboModule> MainApplicationTurboModuleManagerDelegate::getTurboModule(const std::string name, const std::shared_ptr<CallInvoker> jsInvoker) { | ||
// Not implemented yet: provide pure-C++ NativeModules here. | ||
return nullptr; | ||
} | ||
|
||
std::shared_ptr<TurboModule> MainApplicationTurboModuleManagerDelegate::getTurboModule(const std::string name, const JavaTurboModule::InitParams ¶ms) { | ||
return MainApplicationModuleProvider(name, params); | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
30 changes: 30 additions & 0 deletions
30
android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <memory> | ||
#include <string> | ||
|
||
#include <ReactCommon/TurboModuleManagerDelegate.h> | ||
#include <fbjni/fbjni.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
class MainApplicationTurboModuleManagerDelegate : public jni::HybridClass<MainApplicationTurboModuleManagerDelegate, TurboModuleManagerDelegate> { | ||
public: | ||
// Adapt it to the package you used for your Java class. | ||
static constexpr auto kJavaDescriptor = | ||
"Lcom/rnnewarchitectureapp/modules/MainApplicationTurboModuleManagerDelegate;"; | ||
|
||
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>); | ||
|
||
static void registerNatives(); | ||
|
||
std::shared_ptr<TurboModule> getTurboModule(const std::string name, const std::shared_ptr<CallInvoker> jsInvoker) override; | ||
std::shared_ptr<TurboModule> getTurboModule(const std::string name, const JavaTurboModule::InitParams ¶ms) override; | ||
|
||
private: | ||
friend HybridBase; | ||
using HybridBase::HybridBase; | ||
|
||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <fbjni/fbjni.h> | ||
#include "MainApplicationTurboModuleManagerDelegate.h" | ||
|
||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { | ||
return facebook::jni::initialize(vm, [] { | ||
facebook::react::MainApplicationTurboModuleManagerDelegate::registerNatives(); | ||
}); | ||
} |