Skip to content

Commit

Permalink
[TurboModule] Add the C++ implementation for MainApplicationTurboModu…
Browse files Browse the repository at this point in the history
…leManagerDelegate
  • Loading branch information
cortinico committed Feb 28, 2022
1 parent f6d2e81 commit d8884c2
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
19 changes: 19 additions & 0 deletions android/app/src/main/jni/MainApplicationModuleProvider.cpp
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 &params) {
auto module = answersolver_ModuleProvider(moduleName, params);
if (module != nullptr) {
return module;
}

return rncore_ModuleProvider(moduleName, params);
}

} // namespace react
} // namespace facebook
14 changes: 14 additions & 0 deletions android/app/src/main/jni/MainApplicationModuleProvider.h
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 &params);

} // namespace react
} // namespace facebook
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 &params) {
return MainApplicationModuleProvider(name, params);
}

} // namespace react
} // namespace facebook
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 &params) override;

private:
friend HybridBase;
using HybridBase::HybridBase;

};

} // namespace react
} // namespace facebook
8 changes: 8 additions & 0 deletions android/app/src/main/jni/OnLoad.cpp
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();
});
}

0 comments on commit d8884c2

Please sign in to comment.