mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Move TurboModule Core from ReactCommon/turbomodule to ReactCommon/react/nativemodule
Summary: This diff moves the code of TurboModule Core from ReactCommon/turbomodule to ReactCommon/react/nativemodule For iOS: Pod spec name stays as "ReactCommon/turbomodule/..." for now, only the source/header location is affected. The target will be renamed/restructured closer to TurboModule rollout. changelog: [internal] Internal Reviewed By: RSNara Differential Revision: D23362253 fbshipit-source-id: c2c8207578e50821c7573255d4319b9051b58a37
This commit is contained in:
committed by
Facebook GitHub Bot
parent
57dd48b246
commit
7c93f5b001
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "SampleTurboCxxModule.h"
|
||||
|
||||
#include <ReactCommon/TurboModuleUtils.h>
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
SampleTurboCxxModule::SampleTurboCxxModule(
|
||||
std::shared_ptr<CallInvoker> jsInvoker)
|
||||
: NativeSampleTurboCxxModuleSpecJSI(jsInvoker) {}
|
||||
|
||||
void SampleTurboCxxModule::voidFunc(jsi::Runtime &rt) {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
bool SampleTurboCxxModule::getBool(jsi::Runtime &rt, bool arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
double SampleTurboCxxModule::getNumber(jsi::Runtime &rt, double arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
jsi::String SampleTurboCxxModule::getString(
|
||||
jsi::Runtime &rt,
|
||||
const jsi::String &arg) {
|
||||
return jsi::String::createFromUtf8(rt, arg.utf8(rt));
|
||||
}
|
||||
|
||||
jsi::Array SampleTurboCxxModule::getArray(
|
||||
jsi::Runtime &rt,
|
||||
const jsi::Array &arg) {
|
||||
return deepCopyJSIArray(rt, arg);
|
||||
}
|
||||
|
||||
jsi::Object SampleTurboCxxModule::getObject(
|
||||
jsi::Runtime &rt,
|
||||
const jsi::Object &arg) {
|
||||
return deepCopyJSIObject(rt, arg);
|
||||
}
|
||||
|
||||
jsi::Object SampleTurboCxxModule::getValue(
|
||||
jsi::Runtime &rt,
|
||||
double x,
|
||||
const jsi::String &y,
|
||||
const jsi::Object &z) {
|
||||
// Note: return type isn't type-safe.
|
||||
jsi::Object result(rt);
|
||||
result.setProperty(rt, "x", jsi::Value(x));
|
||||
result.setProperty(rt, "y", jsi::String::createFromUtf8(rt, y.utf8(rt)));
|
||||
result.setProperty(rt, "z", deepCopyJSIObject(rt, z));
|
||||
return result;
|
||||
}
|
||||
|
||||
void SampleTurboCxxModule::getValueWithCallback(
|
||||
jsi::Runtime &rt,
|
||||
const jsi::Function &callback) {
|
||||
callback.call(rt, jsi::String::createFromUtf8(rt, "value from callback!"));
|
||||
}
|
||||
|
||||
jsi::Value SampleTurboCxxModule::getValueWithPromise(
|
||||
jsi::Runtime &rt,
|
||||
bool error) {
|
||||
return createPromiseAsJSIValue(
|
||||
rt, [error](jsi::Runtime &rt2, std::shared_ptr<Promise> promise) {
|
||||
if (error) {
|
||||
promise->reject("intentional promise rejection");
|
||||
} else {
|
||||
promise->resolve(jsi::String::createFromUtf8(rt2, "result!"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
jsi::Object SampleTurboCxxModule::getConstants(jsi::Runtime &rt) {
|
||||
// Note: return type isn't type-safe.
|
||||
jsi::Object result(rt);
|
||||
result.setProperty(rt, "const1", jsi::Value(true));
|
||||
result.setProperty(rt, "const2", jsi::Value(375));
|
||||
result.setProperty(
|
||||
rt, "const3", jsi::String::createFromUtf8(rt, "something"));
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
Reference in New Issue
Block a user