react-native/ReactCommon/cxxreact/CxxNativeModule.h
Marc Horowitz e622d51e20 Support ModuleHolder-based lazy init of C++ modules with C++ bridge on android
Reviewed By: AaaChiuuu

Differential Revision: D4614479

fbshipit-source-id: 109ac34b8688f0113675e4a4479d1ddcc6169ed4
2017-03-14 15:35:01 -07:00

41 lines
1.1 KiB
C++

// Copyright 2004-present Facebook. All Rights Reserved.
#pragma once
#include <cxxreact/CxxModule.h>
#include <cxxreact/NativeModule.h>
namespace facebook {
namespace react {
class Instance;
std::function<void(folly::dynamic)> makeCallback(
std::weak_ptr<Instance> instance, ExecutorToken token, const folly::dynamic& callbackId);
class CxxNativeModule : public NativeModule {
public:
CxxNativeModule(std::weak_ptr<Instance> instance, std::string name,
xplat::module::CxxModule::Provider provider);
std::string getName() override;
std::vector<MethodDescriptor> getMethods() override;
folly::dynamic getConstants() override;
bool supportsWebWorkers() override;
void invoke(ExecutorToken token, unsigned int reactMethodId, folly::dynamic&& params) override;
MethodCallResult callSerializableNativeHook(
ExecutorToken token, unsigned int hookId, folly::dynamic&& args) override;
private:
void lazyInit();
std::weak_ptr<Instance> instance_;
std::string name_;
xplat::module::CxxModule::Provider provider_;
std::unique_ptr<xplat::module::CxxModule> module_;
std::vector<xplat::module::CxxModule::Method> methods_;
};
}
}