Format code in ReactCommon/turbomodule/core
Summary: Just ran `arc f ReactCommon/turbomodule/core/**/*`. Reviewed By: ejanzer Differential Revision: D16691807 fbshipit-source-id: 3f499ffeffaae47bda550c0071c93cd7f48e2a23
This commit is contained in:
Родитель
9b1465b74f
Коммит
c237794236
|
@ -11,7 +11,7 @@ namespace facebook {
|
|||
namespace react {
|
||||
|
||||
// LongLivedObjectCollection
|
||||
LongLivedObjectCollection& LongLivedObjectCollection::get() {
|
||||
LongLivedObjectCollection &LongLivedObjectCollection::get() {
|
||||
static LongLivedObjectCollection instance;
|
||||
return instance;
|
||||
}
|
||||
|
|
|
@ -14,18 +14,20 @@ namespace facebook {
|
|||
namespace react {
|
||||
|
||||
/**
|
||||
* A simple wrapper class that can be registered to a collection that keep it alive for extended period of time.
|
||||
* This object can be removed from the collection when needed.
|
||||
* A simple wrapper class that can be registered to a collection that keep it
|
||||
* alive for extended period of time. This object can be removed from the
|
||||
* collection when needed.
|
||||
*
|
||||
* The subclass of this class must be created using std::make_shared<T>().
|
||||
* After creation, add it to the `LongLivedObjectCollection`.
|
||||
* When done with the object, call `allowRelease()` to allow the OS to release it.
|
||||
* When done with the object, call `allowRelease()` to allow the OS to release
|
||||
* it.
|
||||
*/
|
||||
class LongLivedObject {
|
||||
public:
|
||||
public:
|
||||
void allowRelease();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
LongLivedObject();
|
||||
};
|
||||
|
||||
|
@ -33,17 +35,17 @@ protected:
|
|||
* A singleton collection for the `LongLivedObject`s.
|
||||
*/
|
||||
class LongLivedObjectCollection {
|
||||
public:
|
||||
static LongLivedObjectCollection& get();
|
||||
public:
|
||||
static LongLivedObjectCollection &get();
|
||||
|
||||
LongLivedObjectCollection(LongLivedObjectCollection const&) = delete;
|
||||
void operator=(LongLivedObjectCollection const&) = delete;
|
||||
LongLivedObjectCollection(LongLivedObjectCollection const &) = delete;
|
||||
void operator=(LongLivedObjectCollection const &) = delete;
|
||||
|
||||
void add(std::shared_ptr<LongLivedObject> o);
|
||||
void remove(const LongLivedObject *o);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
private:
|
||||
LongLivedObjectCollection();
|
||||
std::unordered_set<std::shared_ptr<LongLivedObject>> collection_;
|
||||
};
|
||||
|
|
|
@ -18,15 +18,20 @@ namespace facebook {
|
|||
namespace react {
|
||||
|
||||
/**
|
||||
* A helper class to convert the legacy CxxModule instance to a TurboModule instance.
|
||||
* This should be used only for migration purpose (to TurboModule), since it's not very performant
|
||||
* due to a lot of back-and-forth value conversions between folly::dynamic and jsi::Value.
|
||||
* A helper class to convert the legacy CxxModule instance to a TurboModule
|
||||
* instance. This should be used only for migration purpose (to TurboModule),
|
||||
* since it's not very performant due to a lot of back-and-forth value
|
||||
* conversions between folly::dynamic and jsi::Value.
|
||||
*/
|
||||
class JSI_EXPORT TurboCxxModule : public TurboModule {
|
||||
public:
|
||||
TurboCxxModule(std::unique_ptr<facebook::xplat::module::CxxModule> cxxModule, std::shared_ptr<JSCallInvoker> jsInvoker);
|
||||
public:
|
||||
TurboCxxModule(
|
||||
std::unique_ptr<facebook::xplat::module::CxxModule> cxxModule,
|
||||
std::shared_ptr<JSCallInvoker> jsInvoker);
|
||||
|
||||
virtual facebook::jsi::Value get(facebook::jsi::Runtime& runtime, const facebook::jsi::PropNameID& propName) override;
|
||||
virtual facebook::jsi::Value get(
|
||||
facebook::jsi::Runtime &runtime,
|
||||
const facebook::jsi::PropNameID &propName) override;
|
||||
|
||||
jsi::Value invokeMethod(
|
||||
jsi::Runtime &runtime,
|
||||
|
@ -35,7 +40,7 @@ public:
|
|||
const jsi::Value *args,
|
||||
size_t count);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<facebook::xplat::module::CxxModule::Method> cxxMethods_;
|
||||
std::unique_ptr<facebook::xplat::module::CxxModule> cxxModule_;
|
||||
};
|
||||
|
|
|
@ -12,13 +12,16 @@ using namespace facebook;
|
|||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
TurboModule::TurboModule(const std::string &name, std::shared_ptr<JSCallInvoker> jsInvoker)
|
||||
: name_(name),
|
||||
jsInvoker_(jsInvoker) {}
|
||||
TurboModule::TurboModule(
|
||||
const std::string &name,
|
||||
std::shared_ptr<JSCallInvoker> jsInvoker)
|
||||
: name_(name), jsInvoker_(jsInvoker) {}
|
||||
|
||||
TurboModule::~TurboModule() {}
|
||||
|
||||
jsi::Value TurboModule::get(jsi::Runtime& runtime, const jsi::PropNameID& propName) {
|
||||
jsi::Value TurboModule::get(
|
||||
jsi::Runtime &runtime,
|
||||
const jsi::PropNameID &propName) {
|
||||
std::string propNameUtf8 = propName.utf8(runtime);
|
||||
auto p = methodMap_.find(propNameUtf8);
|
||||
if (p == methodMap_.end()) {
|
||||
|
@ -27,12 +30,14 @@ jsi::Value TurboModule::get(jsi::Runtime& runtime, const jsi::PropNameID& propNa
|
|||
}
|
||||
MethodMetadata meta = p->second;
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime,
|
||||
propName,
|
||||
meta.argCount,
|
||||
[this, meta](facebook::jsi::Runtime &rt, const facebook::jsi::Value &thisVal, const facebook::jsi::Value *args, size_t count) {
|
||||
return meta.invoker(rt, *this, args, count);
|
||||
});
|
||||
runtime,
|
||||
propName,
|
||||
meta.argCount,
|
||||
[this, meta](
|
||||
facebook::jsi::Runtime &rt,
|
||||
const facebook::jsi::Value &thisVal,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count) { return meta.invoker(rt, *this, args, count); });
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -36,22 +36,26 @@ enum TurboModuleMethodValueKind {
|
|||
* Base HostObject class for every module to be exposed to JS
|
||||
*/
|
||||
class JSI_EXPORT TurboModule : public facebook::jsi::HostObject {
|
||||
public:
|
||||
TurboModule(const std::string &name, std::shared_ptr<JSCallInvoker> jsInvoker);
|
||||
public:
|
||||
TurboModule(
|
||||
const std::string &name,
|
||||
std::shared_ptr<JSCallInvoker> jsInvoker);
|
||||
virtual ~TurboModule();
|
||||
|
||||
virtual facebook::jsi::Value get(facebook::jsi::Runtime& runtime, const facebook::jsi::PropNameID& propName) override;
|
||||
virtual facebook::jsi::Value get(
|
||||
facebook::jsi::Runtime &runtime,
|
||||
const facebook::jsi::PropNameID &propName) override;
|
||||
|
||||
const std::string name_;
|
||||
std::shared_ptr<JSCallInvoker> jsInvoker_;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
struct MethodMetadata {
|
||||
size_t argCount;
|
||||
facebook::jsi::Value (*invoker)(
|
||||
facebook::jsi::Runtime& rt,
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value* args,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count);
|
||||
};
|
||||
|
||||
|
@ -59,10 +63,11 @@ protected:
|
|||
};
|
||||
|
||||
/**
|
||||
* An app/platform-specific provider function to get an instance of a module given a name.
|
||||
* An app/platform-specific provider function to get an instance of a module
|
||||
* given a name.
|
||||
*/
|
||||
using TurboModuleProviderFunctionType = std::function<std::shared_ptr<TurboModule>(
|
||||
const std::string &name)>;
|
||||
using TurboModuleProviderFunctionType =
|
||||
std::function<std::shared_ptr<TurboModule>(const std::string &name)>;
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
|
|
@ -20,8 +20,9 @@ namespace react {
|
|||
/**
|
||||
* Public API to install the TurboModule system.
|
||||
*/
|
||||
TurboModuleBinding::TurboModuleBinding(const TurboModuleProviderFunctionType &moduleProvider)
|
||||
: moduleProvider_(moduleProvider) {}
|
||||
TurboModuleBinding::TurboModuleBinding(
|
||||
const TurboModuleProviderFunctionType &moduleProvider)
|
||||
: moduleProvider_(moduleProvider) {}
|
||||
|
||||
void TurboModuleBinding::install(
|
||||
jsi::Runtime &runtime,
|
||||
|
@ -33,7 +34,11 @@ void TurboModuleBinding::install(
|
|||
runtime,
|
||||
jsi::PropNameID::forAscii(runtime, "__turboModuleProxy"),
|
||||
1,
|
||||
[binding](jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
||||
[binding](
|
||||
jsi::Runtime &rt,
|
||||
const jsi::Value &thisVal,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
return binding->jsProxy(rt, thisVal, args, count);
|
||||
}));
|
||||
}
|
||||
|
@ -48,7 +53,8 @@ void TurboModuleBinding::invalidate() const {
|
|||
// LongLivedObjectCollection::get().clear();
|
||||
}
|
||||
|
||||
std::shared_ptr<TurboModule> TurboModuleBinding::getModule(const std::string &name) {
|
||||
std::shared_ptr<TurboModule> TurboModuleBinding::getModule(
|
||||
const std::string &name) {
|
||||
std::shared_ptr<TurboModule> module = nullptr;
|
||||
{
|
||||
SystraceSection s("TurboModuleBinding::getModule", "module", name);
|
||||
|
@ -58,12 +64,13 @@ std::shared_ptr<TurboModule> TurboModuleBinding::getModule(const std::string &na
|
|||
}
|
||||
|
||||
jsi::Value TurboModuleBinding::jsProxy(
|
||||
jsi::Runtime& runtime,
|
||||
const jsi::Value& thisVal,
|
||||
const jsi::Value* args,
|
||||
jsi::Runtime &runtime,
|
||||
const jsi::Value &thisVal,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
if (count != 1) {
|
||||
throw std::invalid_argument("TurboModuleBinding::jsProxy arg count must be 1");
|
||||
throw std::invalid_argument(
|
||||
"TurboModuleBinding::jsProxy arg count must be 1");
|
||||
}
|
||||
std::string moduleName = args[0].getString(runtime).utf8(runtime);
|
||||
std::shared_ptr<TurboModule> module = getModule(moduleName);
|
||||
|
|
|
@ -21,7 +21,7 @@ class JSCallInvoker;
|
|||
* Represents the JavaScript binding for the TurboModule system.
|
||||
*/
|
||||
class TurboModuleBinding {
|
||||
public:
|
||||
public:
|
||||
/*
|
||||
* Installs TurboModuleBinding into JavaScript runtime.
|
||||
* Thread synchronization must be enforced externally.
|
||||
|
@ -43,15 +43,15 @@ public:
|
|||
*/
|
||||
std::shared_ptr<TurboModule> getModule(const std::string &name);
|
||||
|
||||
private:
|
||||
private:
|
||||
/**
|
||||
* A lookup function exposed to JS to get an instance of a TurboModule
|
||||
* for the given name.
|
||||
*/
|
||||
jsi::Value jsProxy(
|
||||
jsi::Runtime& runtime,
|
||||
const jsi::Value& thisVal,
|
||||
const jsi::Value* args,
|
||||
jsi::Runtime &runtime,
|
||||
const jsi::Value &thisVal,
|
||||
const jsi::Value *args,
|
||||
size_t count);
|
||||
|
||||
TurboModuleProviderFunctionType moduleProvider_;
|
||||
|
|
|
@ -57,15 +57,14 @@ jsi::Array deepCopyJSIArray(jsi::Runtime &rt, const jsi::Array &arr) {
|
|||
size_t size = arr.size(rt);
|
||||
jsi::Array copy(rt, size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
copy.setValueAtIndex(rt, i, deepCopyJSIValue(rt, arr.getValueAtIndex(rt, i)));
|
||||
copy.setValueAtIndex(
|
||||
rt, i, deepCopyJSIValue(rt, arr.getValueAtIndex(rt, i)));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
Promise::Promise(jsi::Runtime &rt, jsi::Function resolve, jsi::Function reject)
|
||||
: runtime_(rt),
|
||||
resolve_(std::move(resolve)),
|
||||
reject_(std::move(reject)) {}
|
||||
: runtime_(rt), resolve_(std::move(resolve)), reject_(std::move(reject)) {}
|
||||
|
||||
void Promise::resolve(const jsi::Value &result) {
|
||||
resolve_.call(runtime_, result);
|
||||
|
@ -73,20 +72,28 @@ void Promise::resolve(const jsi::Value &result) {
|
|||
|
||||
void Promise::reject(const std::string &message) {
|
||||
jsi::Object error(runtime_);
|
||||
error.setProperty(runtime_, "message", jsi::String::createFromUtf8(runtime_, message));
|
||||
error.setProperty(
|
||||
runtime_, "message", jsi::String::createFromUtf8(runtime_, message));
|
||||
reject_.call(runtime_, error);
|
||||
}
|
||||
|
||||
jsi::Value createPromiseAsJSIValue(jsi::Runtime &rt, const PromiseSetupFunctionType func) {
|
||||
jsi::Value createPromiseAsJSIValue(
|
||||
jsi::Runtime &rt,
|
||||
const PromiseSetupFunctionType func) {
|
||||
jsi::Function JSPromise = rt.global().getPropertyAsFunction(rt, "Promise");
|
||||
jsi::Function fn = jsi::Function::createFromHostFunction(
|
||||
rt,
|
||||
jsi::PropNameID::forAscii(rt, "fn"),
|
||||
2,
|
||||
[func](jsi::Runtime &rt2, const jsi::Value &thisVal, const jsi::Value *args, size_t count) {
|
||||
[func](
|
||||
jsi::Runtime &rt2,
|
||||
const jsi::Value &thisVal,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
jsi::Function resolve = args[0].getObject(rt2).getFunction(rt2);
|
||||
jsi::Function reject = args[1].getObject(rt2).getFunction(rt2);
|
||||
auto wrapper = std::make_shared<Promise>(rt2, std::move(resolve), std::move(reject));
|
||||
auto wrapper = std::make_shared<Promise>(
|
||||
rt2, std::move(resolve), std::move(reject));
|
||||
func(rt2, wrapper);
|
||||
return jsi::Value::undefined();
|
||||
});
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
#import <string>
|
||||
#import <unordered_map>
|
||||
|
||||
#define RCT_IS_TURBO_MODULE_CLASS(klass) ((RCTTurboModuleEnabled() && [(klass) conformsToProtocol:@protocol(RCTTurboModule)]))
|
||||
#define RCT_IS_TURBO_MODULE_CLASS(klass) \
|
||||
((RCTTurboModuleEnabled() && [(klass) conformsToProtocol:@protocol(RCTTurboModule)]))
|
||||
#define RCT_IS_TURBO_MODULE_INSTANCE(module) RCT_IS_TURBO_MODULE_CLASS([(module) class])
|
||||
|
||||
namespace facebook {
|
||||
|
@ -30,7 +31,7 @@ class Instance;
|
|||
* ObjC++ specific TurboModule base class.
|
||||
*/
|
||||
class JSI_EXPORT ObjCTurboModule : public TurboModule {
|
||||
public:
|
||||
public:
|
||||
ObjCTurboModule(const std::string &name, id<RCTTurboModule> instance, std::shared_ptr<JSCallInvoker> jsInvoker);
|
||||
|
||||
jsi::Value invokeObjCMethod(
|
||||
|
@ -42,27 +43,29 @@ public:
|
|||
size_t count);
|
||||
|
||||
id<RCTTurboModule> instance_;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void setMethodArgConversionSelector(NSString *methodName, int argIndex, NSString *fnName);
|
||||
private:
|
||||
|
||||
private:
|
||||
/**
|
||||
* TODO(ramanpreet):
|
||||
* Investigate an optimization that'll let us get rid of this NSMutableDictionary.
|
||||
*/
|
||||
NSMutableDictionary<NSString *, NSMutableArray *> *methodArgConversionSelectors_;
|
||||
NSDictionary<NSString *, NSArray<NSString *> *> *methodArgumentTypeNames_;
|
||||
NSString* getArgumentTypeName(NSString* methodName, int argIndex);
|
||||
NSString *getArgumentTypeName(NSString *methodName, int argIndex);
|
||||
|
||||
NSInvocation *getMethodInvocation(
|
||||
jsi::Runtime &runtime,
|
||||
TurboModuleMethodValueKind valueKind,
|
||||
const id<RCTTurboModule> module,
|
||||
std::shared_ptr<JSCallInvoker> jsInvoker,
|
||||
const std::string& methodName,
|
||||
SEL selector,
|
||||
const jsi::Value *args,
|
||||
size_t count,
|
||||
NSMutableArray *retainedObjectsForInvocation);
|
||||
jsi::Runtime &runtime,
|
||||
TurboModuleMethodValueKind valueKind,
|
||||
const id<RCTTurboModule> module,
|
||||
std::shared_ptr<JSCallInvoker> jsInvoker,
|
||||
const std::string &methodName,
|
||||
SEL selector,
|
||||
const jsi::Value *args,
|
||||
size_t count,
|
||||
NSMutableArray *retainedObjectsForInvocation);
|
||||
|
||||
BOOL hasMethodArgConversionSelector(NSString *methodName, int argIndex);
|
||||
SEL getMethodArgConversionSelector(NSString *methodName, int argIndex);
|
||||
|
@ -84,7 +87,8 @@ private:
|
|||
|
||||
@optional
|
||||
// This should be required, after migration is done.
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker;
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:
|
||||
(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
// TODO: Move to xplat codegen.
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
|
||||
instance:(id<RCTTurboModule>)instance
|
||||
jsInvoker:(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker;
|
||||
jsInvoker:
|
||||
(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker;
|
||||
|
||||
@optional
|
||||
|
||||
|
@ -30,11 +31,12 @@
|
|||
* Create an instance of a TurboModule without relying on any ObjC++ module instance.
|
||||
*/
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
|
||||
jsInvoker:(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker;
|
||||
jsInvoker:
|
||||
(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker;
|
||||
|
||||
@end
|
||||
|
||||
@interface RCTTurboModuleManager : NSObject<RCTTurboModuleLookupDelegate>
|
||||
@interface RCTTurboModuleManager : NSObject <RCTTurboModuleLookupDelegate>
|
||||
|
||||
- (instancetype)initWithBridge:(RCTBridge *)bridge delegate:(id<RCTTurboModuleManagerDelegate>)delegate;
|
||||
|
||||
|
|
|
@ -12,62 +12,129 @@
|
|||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_voidFunc(
|
||||
jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)->voidFunc(rt);
|
||||
return jsi::Value::undefined();
|
||||
}
|
||||
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
return jsi::Value(static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)->getBool(rt, args[0].getBool()));
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getBool(
|
||||
jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
return jsi::Value(
|
||||
static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)
|
||||
->getBool(rt, args[0].getBool()));
|
||||
}
|
||||
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
return jsi::Value(static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)->getNumber(rt, args[0].getNumber()));
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getNumber(
|
||||
jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
return jsi::Value(
|
||||
static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)
|
||||
->getNumber(rt, args[0].getNumber()));
|
||||
}
|
||||
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)->getString(rt, args[0].getString(rt));
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getString(
|
||||
jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)
|
||||
->getString(rt, args[0].getString(rt));
|
||||
}
|
||||
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)->getArray(rt, args[0].getObject(rt).getArray(rt));
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getArray(
|
||||
jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)
|
||||
->getArray(rt, args[0].getObject(rt).getArray(rt));
|
||||
}
|
||||
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)->getObject(rt, args[0].getObject(rt));
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getObject(
|
||||
jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)
|
||||
->getObject(rt, args[0].getObject(rt));
|
||||
}
|
||||
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)->getValue(rt, args[0].getNumber(), args[1].getString(rt), args[2].getObject(rt));
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValue(
|
||||
jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)
|
||||
->getValue(
|
||||
rt,
|
||||
args[0].getNumber(),
|
||||
args[1].getString(rt),
|
||||
args[2].getObject(rt));
|
||||
}
|
||||
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)->getValueWithCallback(rt, std::move(args[0].getObject(rt).getFunction(rt)));
|
||||
static jsi::Value
|
||||
__hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValueWithCallback(
|
||||
jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)
|
||||
->getValueWithCallback(
|
||||
rt, std::move(args[0].getObject(rt).getFunction(rt)));
|
||||
return jsi::Value::undefined();
|
||||
}
|
||||
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)->getValueWithPromise(rt, args[0].getBool());
|
||||
static jsi::Value
|
||||
__hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValueWithPromise(
|
||||
jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)
|
||||
->getValueWithPromise(rt, args[0].getBool());
|
||||
}
|
||||
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)->getConstants(rt);
|
||||
static jsi::Value __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getConstants(
|
||||
jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
return static_cast<NativeSampleTurboCxxModuleSpecJSI *>(&turboModule)
|
||||
->getConstants(rt);
|
||||
}
|
||||
|
||||
NativeSampleTurboCxxModuleSpecJSI::NativeSampleTurboCxxModuleSpecJSI(std::shared_ptr<JSCallInvoker> jsInvoker)
|
||||
: TurboModule("SampleTurboCxxModule", jsInvoker) {
|
||||
|
||||
methodMap_["voidFunc"] = MethodMetadata {0, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_voidFunc};
|
||||
methodMap_["getBool"] = MethodMetadata {1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getBool};
|
||||
methodMap_["getNumber"] = MethodMetadata {1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getNumber};
|
||||
methodMap_["getString"] = MethodMetadata {1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getString};
|
||||
methodMap_["getArray"] = MethodMetadata {1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getArray};
|
||||
methodMap_["getObject"] = MethodMetadata {1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getObject};
|
||||
methodMap_["getValue"] = MethodMetadata {3, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValue};
|
||||
methodMap_["getValueWithCallback"] = MethodMetadata {1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValueWithCallback};
|
||||
methodMap_["getValueWithPromise"] = MethodMetadata {1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValueWithPromise};
|
||||
methodMap_["getConstants"] = MethodMetadata {0, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getConstants};
|
||||
|
||||
NativeSampleTurboCxxModuleSpecJSI::NativeSampleTurboCxxModuleSpecJSI(
|
||||
std::shared_ptr<JSCallInvoker> jsInvoker)
|
||||
: TurboModule("SampleTurboCxxModule", jsInvoker) {
|
||||
methodMap_["voidFunc"] = MethodMetadata{
|
||||
0, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_voidFunc};
|
||||
methodMap_["getBool"] = MethodMetadata{
|
||||
1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getBool};
|
||||
methodMap_["getNumber"] = MethodMetadata{
|
||||
1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getNumber};
|
||||
methodMap_["getString"] = MethodMetadata{
|
||||
1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getString};
|
||||
methodMap_["getArray"] = MethodMetadata{
|
||||
1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getArray};
|
||||
methodMap_["getObject"] = MethodMetadata{
|
||||
1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getObject};
|
||||
methodMap_["getValue"] = MethodMetadata{
|
||||
3, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValue};
|
||||
methodMap_["getValueWithCallback"] = MethodMetadata{
|
||||
1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValueWithCallback};
|
||||
methodMap_["getValueWithPromise"] = MethodMetadata{
|
||||
1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getValueWithPromise};
|
||||
methodMap_["getConstants"] = MethodMetadata{
|
||||
0, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getConstants};
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -17,21 +17,26 @@ namespace react {
|
|||
|
||||
// TODO: This definition should be codegen'ed for type-safety purpose.
|
||||
class JSI_EXPORT NativeSampleTurboCxxModuleSpecJSI : public TurboModule {
|
||||
protected:
|
||||
protected:
|
||||
NativeSampleTurboCxxModuleSpecJSI(std::shared_ptr<JSCallInvoker> jsInvoker);
|
||||
|
||||
public:
|
||||
public:
|
||||
virtual void voidFunc(jsi::Runtime &rt) = 0;
|
||||
virtual bool getBool(jsi::Runtime &rt, bool arg) = 0;
|
||||
virtual double getNumber(jsi::Runtime &rt, double arg) = 0;
|
||||
virtual jsi::String getString(jsi::Runtime &rt, const jsi::String &arg) = 0;
|
||||
virtual jsi::Array getArray(jsi::Runtime &rt, const jsi::Array &arg) = 0;
|
||||
virtual jsi::Object getObject(jsi::Runtime &rt, const jsi::Object &arg) = 0;
|
||||
virtual jsi::Object getValue(jsi::Runtime &rt, double x, const jsi::String &y, const jsi::Object &z) = 0;
|
||||
virtual void getValueWithCallback(jsi::Runtime &rt, const jsi::Function &callback) = 0;
|
||||
virtual jsi::Object getValue(
|
||||
jsi::Runtime &rt,
|
||||
double x,
|
||||
const jsi::String &y,
|
||||
const jsi::Object &z) = 0;
|
||||
virtual void getValueWithCallback(
|
||||
jsi::Runtime &rt,
|
||||
const jsi::Function &callback) = 0;
|
||||
virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) = 0;
|
||||
virtual jsi::Object getConstants(jsi::Runtime &rt) = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -26,13 +26,9 @@
|
|||
- (NSString *)getString:(NSString *)arg;
|
||||
- (NSArray<id<NSObject>> *)getArray:(NSArray *)arg;
|
||||
- (NSDictionary *)getObject:(NSDictionary *)arg;
|
||||
- (NSDictionary *)getValue:(double)x
|
||||
y:(NSString *)y
|
||||
z:(NSDictionary *)z;
|
||||
- (NSDictionary *)getValue:(double)x y:(NSString *)y z:(NSDictionary *)z;
|
||||
- (void)getValueWithCallback:(RCTResponseSenderBlock)callback;
|
||||
- (void)getValueWithPromise:(BOOL)error
|
||||
resolve:(RCTPromiseResolveBlock)resolve
|
||||
reject:(RCTPromiseRejectBlock)reject;
|
||||
- (void)getValueWithPromise:(BOOL)error resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
|
||||
- (NSDictionary *)constantsToExport;
|
||||
- (NSDictionary *)getConstants;
|
||||
|
||||
|
@ -45,7 +41,7 @@ namespace react {
|
|||
* The iOS TurboModule impl specific to SampleTurboModule.
|
||||
*/
|
||||
class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public ObjCTurboModule {
|
||||
public:
|
||||
public:
|
||||
NativeSampleTurboModuleSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<JSCallInvoker> jsInvoker);
|
||||
};
|
||||
|
||||
|
|
|
@ -10,69 +10,124 @@
|
|||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc(
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count)
|
||||
{
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(rt, VoidKind, "voidFunc", @selector(voidFunc), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getBool(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getBool(
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count)
|
||||
{
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(rt, BooleanKind, "getBool", @selector(getBool:), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getNumber(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getNumber(
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count)
|
||||
{
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(rt, NumberKind, "getNumber", @selector(getNumber:), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getString(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getString(
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count)
|
||||
{
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(rt, StringKind, "getString", @selector(getString:), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getArray(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getArray(
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count)
|
||||
{
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(rt, ArrayKind, "getArray", @selector(getArray:), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getObject(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getObject(
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count)
|
||||
{
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(rt, ObjectKind, "getObject", @selector(getObject:), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getValue(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getValue(
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count)
|
||||
{
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(rt, ObjectKind, "getValue", @selector(getValue:y:z:), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback(
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count)
|
||||
{
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(rt, VoidKind, "getValueWithCallback", @selector(getValueWithCallback:), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise(
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count)
|
||||
{
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(
|
||||
rt, PromiseKind, "getValueWithPromise", @selector(getValueWithPromise:resolve:reject:), args, count);
|
||||
}
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants(
|
||||
facebook::jsi::Runtime &rt,
|
||||
TurboModule &turboModule,
|
||||
const facebook::jsi::Value *args,
|
||||
size_t count)
|
||||
{
|
||||
return static_cast<ObjCTurboModule &>(turboModule)
|
||||
.invokeObjCMethod(rt, ObjectKind, "getConstants", @selector(getConstants), args, count);
|
||||
}
|
||||
|
||||
NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<JSCallInvoker> jsInvoker)
|
||||
: ObjCTurboModule("SampleTurboModule", instance, jsInvoker) {
|
||||
methodMap_["voidFunc"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc};
|
||||
methodMap_["getBool"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getBool};
|
||||
methodMap_["getNumber"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getNumber};
|
||||
methodMap_["getString"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getString};
|
||||
methodMap_["getArray"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getArray};
|
||||
methodMap_["getObject"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getObject};
|
||||
methodMap_["getValue"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleSpecJSI_getValue};
|
||||
methodMap_["getValueWithCallback"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback};
|
||||
methodMap_["getValueWithPromise"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise};
|
||||
methodMap_["getConstants"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants};
|
||||
NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(
|
||||
id<RCTTurboModule> instance,
|
||||
std::shared_ptr<JSCallInvoker> jsInvoker)
|
||||
: ObjCTurboModule("SampleTurboModule", instance, jsInvoker)
|
||||
{
|
||||
methodMap_["voidFunc"] = MethodMetadata{0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc};
|
||||
methodMap_["getBool"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getBool};
|
||||
methodMap_["getNumber"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getNumber};
|
||||
methodMap_["getString"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getString};
|
||||
methodMap_["getArray"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getArray};
|
||||
methodMap_["getObject"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getObject};
|
||||
methodMap_["getValue"] = MethodMetadata{3, __hostFunction_NativeSampleTurboModuleSpecJSI_getValue};
|
||||
methodMap_["getValueWithCallback"] =
|
||||
MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback};
|
||||
methodMap_["getValueWithPromise"] =
|
||||
MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise};
|
||||
methodMap_["getConstants"] = MethodMetadata{0, __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants};
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
* With jsi::HostObject, this class is no longer necessary, but the system supports it for
|
||||
* backward compatibility.
|
||||
*/
|
||||
@interface RCTSampleTurboCxxModule_v1 : RCTCxxModule<RCTTurboModule>
|
||||
@interface RCTSampleTurboCxxModule_v1 : RCTCxxModule <RCTTurboModule>
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* Second variant of a sample backward-compatible RCTCxxModule-based module.
|
||||
*/
|
||||
@interface RCTSampleTurboCxxModule_v2 : RCTCxxModule<RCTTurboModule>
|
||||
@interface RCTSampleTurboCxxModule_v2 : RCTCxxModule <RCTTurboModule>
|
||||
|
||||
@end
|
||||
|
|
|
@ -13,6 +13,6 @@
|
|||
* Sample iOS-specific impl of a TurboModule, conforming to the spec protocol.
|
||||
* This class is also 100% compatible with the NativeModule system.
|
||||
*/
|
||||
@interface RCTSampleTurboModule : NSObject<NativeSampleTurboModuleSpec>
|
||||
@interface RCTSampleTurboModule : NSObject <NativeSampleTurboModuleSpec>
|
||||
|
||||
@end
|
||||
|
|
|
@ -30,7 +30,8 @@ RCT_EXPORT_MODULE()
|
|||
return dispatch_get_main_queue();
|
||||
}
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:
|
||||
(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker
|
||||
{
|
||||
return std::make_shared<NativeSampleTurboModuleSpecJSI>(self, jsInvoker);
|
||||
}
|
||||
|
@ -48,9 +49,9 @@ RCT_EXPORT_MODULE()
|
|||
CGSize screenSize = mainScreen.bounds.size;
|
||||
|
||||
return @{
|
||||
@"const1": @YES,
|
||||
@"const2": @(screenSize.width),
|
||||
@"const3": @"something",
|
||||
@"const1" : @YES,
|
||||
@"const2" : @(screenSize.width),
|
||||
@"const3" : @"something",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -65,56 +66,62 @@ RCT_EXPORT_METHOD(voidFunc)
|
|||
// Nothing to do
|
||||
}
|
||||
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getBool:(BOOL)arg)
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getBool : (BOOL)arg)
|
||||
{
|
||||
return @(arg);
|
||||
}
|
||||
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getNumber:(double)arg)
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getNumber : (double)arg)
|
||||
{
|
||||
return @(arg);
|
||||
}
|
||||
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getString:(NSString *)arg)
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getString : (NSString *)arg)
|
||||
{
|
||||
return arg;
|
||||
}
|
||||
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSArray<id<NSObject>> *, getArray:(NSArray *)arg)
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSArray<id<NSObject>> *, getArray : (NSArray *)arg)
|
||||
{
|
||||
return arg;
|
||||
}
|
||||
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getObject:(NSDictionary *)arg)
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getObject : (NSDictionary *)arg)
|
||||
{
|
||||
return arg;
|
||||
}
|
||||
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getValue:(double)x y:(NSString *)y z:(NSDictionary *)z)
|
||||
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getValue : (double)x y : (NSString *)y z : (NSDictionary *)z)
|
||||
{
|
||||
return @{
|
||||
@"x": @(x),
|
||||
@"y": y ?: [NSNull null],
|
||||
@"z": z ?: [NSNull null],
|
||||
@"x" : @(x),
|
||||
@"y" : y ?: [NSNull null],
|
||||
@"z" : z ?: [NSNull null],
|
||||
};
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(getValueWithCallback:(RCTResponseSenderBlock)callback)
|
||||
RCT_EXPORT_METHOD(getValueWithCallback : (RCTResponseSenderBlock)callback)
|
||||
{
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
callback(@[@"value from callback!"]);
|
||||
callback(@[ @"value from callback!" ]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(getValueWithPromise:(BOOL)error resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXPORT_METHOD(getValueWithPromise
|
||||
: (BOOL)error resolve
|
||||
: (RCTPromiseResolveBlock)resolve reject
|
||||
: (RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
if (!resolve || !reject) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
reject(@"code_1", @"intentional promise rejection", [NSError errorWithDomain:@"RCTSampleTurboModule" code:1 userInfo:nil]);
|
||||
reject(
|
||||
@"code_1",
|
||||
@"intentional promise rejection",
|
||||
[NSError errorWithDomain:@"RCTSampleTurboModule" code:1 userInfo:nil]);
|
||||
} else {
|
||||
resolve(@"result!");
|
||||
}
|
||||
|
|
|
@ -20,76 +20,77 @@ std::string SampleTurboCxxModuleLegacyImpl::getName() {
|
|||
return "SampleTurboCxxModule_v2";
|
||||
}
|
||||
|
||||
std::map<std::string, folly::dynamic> SampleTurboCxxModuleLegacyImpl::getConstants() {
|
||||
std::map<std::string, folly::dynamic>
|
||||
SampleTurboCxxModuleLegacyImpl::getConstants() {
|
||||
return {
|
||||
{"const1", true},
|
||||
{"const2", 375},
|
||||
{"const3", "something"},
|
||||
{"const1", true},
|
||||
{"const2", 375},
|
||||
{"const3", "something"},
|
||||
};
|
||||
};
|
||||
|
||||
std::vector<CxxModule::Method> SampleTurboCxxModuleLegacyImpl::getMethods() {
|
||||
return {
|
||||
CxxModule::Method(
|
||||
"voidFunc",
|
||||
[this](folly::dynamic args) {
|
||||
voidFunc();
|
||||
}),
|
||||
CxxModule::Method(
|
||||
"getBool",
|
||||
[this](folly::dynamic args) {
|
||||
return getBool(xplat::jsArgAsBool(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getNumber",
|
||||
[this](folly::dynamic args) {
|
||||
return getNumber(xplat::jsArgAsDouble(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getString",
|
||||
[this](folly::dynamic args) {
|
||||
return getString(xplat::jsArgAsString(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getString",
|
||||
[this](folly::dynamic args) {
|
||||
return getString(xplat::jsArgAsString(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getArray",
|
||||
[this](folly::dynamic args) {
|
||||
return getArray(xplat::jsArgAsArray(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getObject",
|
||||
[this](folly::dynamic args) {
|
||||
return getObject(xplat::jsArgAsObject(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getValue",
|
||||
[this](folly::dynamic args) {
|
||||
return getValue(
|
||||
xplat::jsArgAsDouble(args, 0),
|
||||
xplat::jsArgAsString(args, 1),
|
||||
xplat::jsArgAsObject(args, 2));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getValueWithCallback",
|
||||
[this](folly::dynamic args, CxxModule::Callback callback) {
|
||||
getValueWithCallback(callback);
|
||||
}),
|
||||
CxxModule::Method(
|
||||
"getValueWithPromise",
|
||||
[this](folly::dynamic args, CxxModule::Callback resolve, CxxModule::Callback reject) {
|
||||
getValueWithPromise(xplat::jsArgAsBool(args, 0), resolve, reject);
|
||||
}),
|
||||
CxxModule::Method(
|
||||
"voidFunc", [this](folly::dynamic args) { voidFunc(); }),
|
||||
CxxModule::Method(
|
||||
"getBool",
|
||||
[this](folly::dynamic args) {
|
||||
return getBool(xplat::jsArgAsBool(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getNumber",
|
||||
[this](folly::dynamic args) {
|
||||
return getNumber(xplat::jsArgAsDouble(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getString",
|
||||
[this](folly::dynamic args) {
|
||||
return getString(xplat::jsArgAsString(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getString",
|
||||
[this](folly::dynamic args) {
|
||||
return getString(xplat::jsArgAsString(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getArray",
|
||||
[this](folly::dynamic args) {
|
||||
return getArray(xplat::jsArgAsArray(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getObject",
|
||||
[this](folly::dynamic args) {
|
||||
return getObject(xplat::jsArgAsObject(args, 0));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getValue",
|
||||
[this](folly::dynamic args) {
|
||||
return getValue(
|
||||
xplat::jsArgAsDouble(args, 0),
|
||||
xplat::jsArgAsString(args, 1),
|
||||
xplat::jsArgAsObject(args, 2));
|
||||
},
|
||||
CxxModule::SyncTag),
|
||||
CxxModule::Method(
|
||||
"getValueWithCallback",
|
||||
[this](folly::dynamic args, CxxModule::Callback callback) {
|
||||
getValueWithCallback(callback);
|
||||
}),
|
||||
CxxModule::Method(
|
||||
"getValueWithPromise",
|
||||
[this](
|
||||
folly::dynamic args,
|
||||
CxxModule::Callback resolve,
|
||||
CxxModule::Callback reject) {
|
||||
getValueWithPromise(xplat::jsArgAsBool(args, 0), resolve, reject);
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -109,30 +110,37 @@ std::string SampleTurboCxxModuleLegacyImpl::getString(const std::string &arg) {
|
|||
return arg;
|
||||
}
|
||||
|
||||
folly::dynamic SampleTurboCxxModuleLegacyImpl::getArray(const folly::dynamic &arg) {
|
||||
folly::dynamic SampleTurboCxxModuleLegacyImpl::getArray(
|
||||
const folly::dynamic &arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
folly::dynamic SampleTurboCxxModuleLegacyImpl::getObject(const folly::dynamic &arg) {
|
||||
folly::dynamic SampleTurboCxxModuleLegacyImpl::getObject(
|
||||
const folly::dynamic &arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
folly::dynamic SampleTurboCxxModuleLegacyImpl::getValue(double x, const std::string &y, const folly::dynamic &z) {
|
||||
return folly::dynamic::object
|
||||
("x", x)
|
||||
("y", y)
|
||||
("z", z);
|
||||
folly::dynamic SampleTurboCxxModuleLegacyImpl::getValue(
|
||||
double x,
|
||||
const std::string &y,
|
||||
const folly::dynamic &z) {
|
||||
return folly::dynamic::object("x", x)("y", y)("z", z);
|
||||
}
|
||||
|
||||
void SampleTurboCxxModuleLegacyImpl::getValueWithCallback(const CxxModule::Callback &callback) {
|
||||
void SampleTurboCxxModuleLegacyImpl::getValueWithCallback(
|
||||
const CxxModule::Callback &callback) {
|
||||
callback({"value from callback!"});
|
||||
}
|
||||
|
||||
void SampleTurboCxxModuleLegacyImpl::getValueWithPromise(bool error, const CxxModule::Callback &resolve, const CxxModule::Callback &reject) {
|
||||
void SampleTurboCxxModuleLegacyImpl::getValueWithPromise(
|
||||
bool error,
|
||||
const CxxModule::Callback &resolve,
|
||||
const CxxModule::Callback &reject) {
|
||||
if (!error) {
|
||||
resolve({"result!"});
|
||||
} else {
|
||||
reject({folly::dynamic::object("message", "intentional promise rejection")});
|
||||
reject(
|
||||
{folly::dynamic::object("message", "intentional promise rejection")});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,9 @@ namespace react {
|
|||
/**
|
||||
* A sample CxxModule (legacy system) implementation.
|
||||
*/
|
||||
class SampleTurboCxxModuleLegacyImpl : public facebook::xplat::module::CxxModule {
|
||||
public:
|
||||
class SampleTurboCxxModuleLegacyImpl
|
||||
: public facebook::xplat::module::CxxModule {
|
||||
public:
|
||||
SampleTurboCxxModuleLegacyImpl();
|
||||
|
||||
std::string getName() override;
|
||||
|
@ -30,9 +31,14 @@ public:
|
|||
std::string getString(const std::string &arg);
|
||||
folly::dynamic getArray(const folly::dynamic &arg);
|
||||
folly::dynamic getObject(const folly::dynamic &arg);
|
||||
folly::dynamic getValue(double x, const std::string &y, const folly::dynamic &z);
|
||||
void getValueWithCallback(const facebook::xplat::module::CxxModule::Callback &callback);
|
||||
void getValueWithPromise(bool error, const facebook::xplat::module::CxxModule::Callback &resolve, const facebook::xplat::module::CxxModule::Callback &reject);
|
||||
folly::dynamic
|
||||
getValue(double x, const std::string &y, const folly::dynamic &z);
|
||||
void getValueWithCallback(
|
||||
const facebook::xplat::module::CxxModule::Callback &callback);
|
||||
void getValueWithPromise(
|
||||
bool error,
|
||||
const facebook::xplat::module::CxxModule::Callback &resolve,
|
||||
const facebook::xplat::module::CxxModule::Callback &reject);
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
|
Загрузка…
Ссылка в новой задаче