feat(smart-app): implement complete mobile app MVP

- App.tsx: full navigation (Auth stack + Main tabs with 5 screens)
- Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen
- HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors
- MapScreen: interactive map with layer toggles (6 layers)
- MarketplaceScreen: categories (6), products (5), search
- ChatScreen: AI chat with quick prompts (4), bot responses
- ProfileScreen: user info, stats, menu (9 items), logout
- AlertsScreen: alert list with severity, acknowledge
- SensorsScreen: sensor list with type filters (6 types), search
- ZonesScreen: zone cards with stats
- SettingsScreen: language picker (FR/EN/ES/DE), privacy, about
- Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n
- Hooks: useSensors, useAlerts, useNotifications, useLocation
- Components: Card, Button, LoadingSpinner, ErrorBoundary, Header
- Services: iotService, notificationService (with axios API client)
- Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN)
- Theme: colors.ts with full design system (Blue Ocean palette)
- Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
This commit is contained in:
Eric FELIXINE
2026-06-01 18:00:35 -04:00
parent 08ca495bde
commit e30ae8ed09
35578 changed files with 3703534 additions and 43 deletions

View File

@@ -0,0 +1,76 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
require "json"
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "..", "..", "package.json")))
version = package['version']
source = { :git => 'https://github.com/facebook/react-native.git' }
if version == '1000.0.0'
# This is an unpublished version, use the latest commit hash of the react-native repo, which were presumably in.
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1")
else
source[:tag] = "v#{version}"
end
folly_config = get_folly_config()
folly_compiler_flags = folly_config[:compiler_flags]
folly_version = folly_config[:version]
boost_compiler_flags = '-Wno-documentation'
using_hermes = ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == "1"
header_search_paths = [
"\"$(PODS_ROOT)/boost\"",
"\"$(PODS_ROOT)/RCT-Folly\"",
"\"$(PODS_ROOT)/DoubleConversion\"",
"\"$(PODS_ROOT)/fmt/include\"",
"\"$(PODS_ROOT)/Headers/Private/React-Core\"",
]
create_header_search_path_for_frameworks("ReactCommon-Samples").each { |search_path| header_search_paths << "\"#{search_path}\""}
Pod::Spec.new do |s|
s.name = "ReactCommon-Samples"
s.module_name = "ReactCommon_Samples"
s.header_dir = "ReactCommon"
s.version = version
s.summary = "-" # TODO
s.homepage = "https://reactnative.dev/"
s.license = package["license"]
s.author = "Meta Platforms, Inc. and its affiliates"
s.platforms = min_supported_versions
s.source = source
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags
s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => header_search_paths,
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = './'
end
s.source_files = "ReactCommon/**/*.{cpp,h}",
"platform/ios/**/*.{mm,cpp,h}"
s.dependency "RCT-Folly"
s.dependency "DoubleConversion"
s.dependency "fmt", "9.1.0"
s.dependency "React-Core"
s.dependency "React-cxxreact"
s.dependency "React-jsi"
add_dependency(s, "React-Codegen", :additional_framework_paths => ["build/generated/ios"])
add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"])
add_dependency(s, "React-NativeModulesApple", :additional_framework_paths => ["build/generated/ios"])
if using_hermes
s.dependency "hermes-engine"
else
s.dependency "React-jsc"
end
end

View File

@@ -0,0 +1,151 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "NativeSampleTurboCxxModuleSpecJSI.h"
// NOTE: This entire file should be codegen'ed.
namespace facebook::react {
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_getEnum(
jsi::Runtime& rt,
TurboModule& turboModule,
const jsi::Value* args,
size_t count) {
return jsi::Value(
static_cast<NativeSampleTurboCxxModuleSpecJSI*>(&turboModule)
->getEnum(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_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_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)));
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_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<CallInvoker> jsInvoker)
: TurboModule("SampleTurboCxxModule", jsInvoker) {
methodMap_["voidFunc"] = MethodMetadata{
0, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_voidFunc};
methodMap_["getBool"] = MethodMetadata{
1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getBool};
methodMap_["getEnum"] = MethodMetadata{
1, __hostFunction_NativeSampleTurboCxxModuleSpecJSI_getEnum};
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 facebook::react

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <memory>
#include <string>
#include <ReactCommon/TurboModule.h>
namespace facebook::react {
// TODO: This definition should be codegen'ed for type-safety purpose.
class JSI_EXPORT NativeSampleTurboCxxModuleSpecJSI : public TurboModule {
protected:
NativeSampleTurboCxxModuleSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
public:
virtual void voidFunc(jsi::Runtime& rt) = 0;
virtual bool getBool(jsi::Runtime& rt, bool arg) = 0;
virtual double getEnum(jsi::Runtime& rt, double 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::Value getValueWithPromise(jsi::Runtime& rt, bool error) = 0;
virtual jsi::Object getConstants(jsi::Runtime& rt) = 0;
};
} // namespace facebook::react

View File

@@ -0,0 +1,96 @@
/*
* Copyright (c) Meta Platforms, Inc. and 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::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::getEnum(jsi::Runtime& rt, double 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 facebook::react

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <memory>
#include "NativeSampleTurboCxxModuleSpecJSI.h"
namespace facebook::react {
/**
* A sample implementation of the C++ spec. In practice, this class can just
* extend jsi::HostObject directly, but using the spec provides build-time
* type-safety.
*/
class SampleTurboCxxModule : public NativeSampleTurboCxxModuleSpecJSI {
public:
SampleTurboCxxModule(std::shared_ptr<CallInvoker> jsInvoker);
void voidFunc(jsi::Runtime& rt) override;
bool getBool(jsi::Runtime& rt, bool arg) override;
double getEnum(jsi::Runtime& rt, double arg) override;
double getNumber(jsi::Runtime& rt, double arg) override;
jsi::String getString(jsi::Runtime& rt, const jsi::String& arg) override;
jsi::Array getArray(jsi::Runtime& rt, const jsi::Array& arg) override;
jsi::Object getObject(jsi::Runtime& rt, const jsi::Object& arg) override;
jsi::Object getValue(
jsi::Runtime& rt,
double x,
const jsi::String& y,
const jsi::Object& z) override;
void getValueWithCallback(jsi::Runtime& rt, const jsi::Function& callback)
override;
jsi::Value getValueWithPromise(jsi::Runtime& rt, bool error) override;
jsi::Object getConstants(jsi::Runtime& rt) override;
};
} // namespace facebook::react

View File

@@ -0,0 +1,26 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)
add_compile_options(
-fexceptions
-frtti
-std=c++20
-Wall
-Wpedantic
-DFOLLY_NO_CONFIG=1
-DLOG_TAG=\"ReactNative\")
file(GLOB sampleturbomodule_SRC CONFIGURE_DEPENDS ReactCommon/*.cpp)
add_library(sampleturbomodule STATIC ${sampleturbomodule_SRC})
target_include_directories(sampleturbomodule PUBLIC .)
target_link_libraries(sampleturbomodule
fbjni
jsi
react_nativemodule_core)

View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// NOTE: This entire file should be codegen'ed.
package com.facebook.fbreact.specs;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
public abstract class NativeSampleTurboModuleSpec extends ReactContextBaseJavaModule
implements TurboModule {
public NativeSampleTurboModuleSpec(ReactApplicationContext reactContext) {
super(reactContext);
}
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract double getNumber(double arg);
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract WritableMap getValue(double x, String y, ReadableMap z);
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract WritableMap getObject(ReadableMap arg);
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract WritableMap getUnsafeObject(ReadableMap arg);
@ReactMethod
public abstract void voidFunc();
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract WritableArray getArray(ReadableArray arg);
@ReactMethod
public abstract void getValueWithPromise(boolean error, Promise promise);
@ReactMethod
public abstract void getValueWithCallback(Callback callback);
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract String getString(String arg);
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract double getRootTag(double arg);
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract boolean getBool(boolean arg);
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract double getEnum(double arg);
@ReactMethod()
public abstract void voidFuncThrows();
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract WritableMap getObjectThrows(ReadableMap arg);
@ReactMethod()
public abstract void promiseThrows(Promise promise);
@ReactMethod()
public abstract void voidFuncAssert();
@ReactMethod(isBlockingSynchronousMethod = true)
public abstract WritableMap getObjectAssert(ReadableMap arg);
@ReactMethod()
public abstract void promiseAssert(Promise promise);
protected abstract Map<String, Object> getTypedExportedConstants();
@Override
public final @Nullable Map<String, Object> getConstants() {
Map<String, Object> constants = getTypedExportedConstants();
if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) {
Set<String> obligatoryFlowConstants =
new HashSet<>(Arrays.asList("const2", "const1", "const3"));
Set<String> optionalFlowConstants = new HashSet<>();
Set<String> undeclaredConstants = new HashSet<>(constants.keySet());
undeclaredConstants.removeAll(obligatoryFlowConstants);
undeclaredConstants.removeAll(optionalFlowConstants);
if (!undeclaredConstants.isEmpty()) {
throw new IllegalStateException(
String.format("Native Module Flow doesn't declare constants: %s", undeclaredConstants));
}
undeclaredConstants = obligatoryFlowConstants;
undeclaredConstants.removeAll(constants.keySet());
if (!undeclaredConstants.isEmpty()) {
throw new IllegalStateException(
String.format("Native Module doesn't fill in constants: %s", undeclaredConstants));
}
}
return constants;
}
}

View File

@@ -0,0 +1,363 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// NOTE: This entire file should be codegen'ed.
#include <ReactCommon/SampleTurboModuleSpec.h>
namespace facebook::react {
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt, VoidKind, "voidFunc", "()V", args, count, cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getBool(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt, BooleanKind, "getBool", "(Z)Z", args, count, cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getEnum(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt, NumberKind, "getEnum", "(D)D", args, count, cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getNumber(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt, NumberKind, "getNumber", "(D)D", args, count, cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getString(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
StringKind,
"getString",
"(Ljava/lang/String;)Ljava/lang/String;",
args,
count,
cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getArray(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
ArrayKind,
"getArray",
"(Lcom/facebook/react/bridge/ReadableArray;)Lcom/facebook/react/bridge/WritableArray;",
args,
count,
cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getObject(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
ObjectKind,
"getObject",
"(Lcom/facebook/react/bridge/ReadableMap;)Lcom/facebook/react/bridge/WritableMap;",
args,
count,
cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getRootTag(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt, NumberKind, "getRootTag", "(D)D", args, count, cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getValue(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
ObjectKind,
"getValue",
"(DLjava/lang/String;Lcom/facebook/react/bridge/ReadableMap;)Lcom/facebook/react/bridge/WritableMap;",
args,
count,
cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
VoidKind,
"getValueWithCallback",
"(Lcom/facebook/react/bridge/Callback;)V",
args,
count,
cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
PromiseKind,
"getValueWithPromise",
"(ZLcom/facebook/react/bridge/Promise;)V",
args,
count,
cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncThrows(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt, VoidKind, "voidFuncThrows", "()V", args, count, cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getObjectThrows(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
ObjectKind,
"getObjectThrows",
"(Lcom/facebook/react/bridge/ReadableMap;)Lcom/facebook/react/bridge/WritableMap;",
args,
count,
cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_promiseThrows(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
PromiseKind,
"promiseThrows",
"(Lcom/facebook/react/bridge/Promise;)V",
args,
count,
cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncAssert(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt, VoidKind, "voidFuncAssert", "()V", args, count, cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getObjectAssert(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
ObjectKind,
"getObjectAssert",
"(Lcom/facebook/react/bridge/ReadableMap;)Lcom/facebook/react/bridge/WritableMap;",
args,
count,
cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_promiseAssert(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
PromiseKind,
"promiseAssert",
"(Lcom/facebook/react/bridge/Promise;)V",
args,
count,
cachedMethodId);
}
static facebook::jsi::Value
__hostFunction_NativeSampleTurboModuleSpecJSI_getConstants(
facebook::jsi::Runtime& rt,
TurboModule& turboModule,
const facebook::jsi::Value* args,
size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule&>(turboModule)
.invokeJavaMethod(
rt,
ObjectKind,
"getConstants",
"()Ljava/util/Map;",
args,
count,
cachedMethodId);
}
NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(
const JavaTurboModule::InitParams& params)
: JavaTurboModule(params) {
methodMap_["voidFunc"] =
MethodMetadata{0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc};
methodMap_["getBool"] =
MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getBool};
methodMap_["getEnum"] =
MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getEnum};
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_["getRootTag"] = MethodMetadata{
1, __hostFunction_NativeSampleTurboModuleSpecJSI_getRootTag};
methodMap_["getValue"] =
MethodMetadata{3, __hostFunction_NativeSampleTurboModuleSpecJSI_getValue};
methodMap_["getValueWithCallback"] = MethodMetadata{
1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback};
methodMap_["getValueWithPromise"] = MethodMetadata{
1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise};
methodMap_["voidFuncThrows"] = MethodMetadata{
0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncThrows};
methodMap_["getObjectThrows"] = MethodMetadata{
1, __hostFunction_NativeSampleTurboModuleSpecJSI_getObjectThrows};
methodMap_["promiseThrows"] = MethodMetadata{
1, __hostFunction_NativeSampleTurboModuleSpecJSI_promiseThrows};
methodMap_["voidFuncAssert"] = MethodMetadata{
0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncAssert};
methodMap_["getObjectAssert"] = MethodMetadata{
1, __hostFunction_NativeSampleTurboModuleSpecJSI_getObjectAssert};
methodMap_["promiseAssert"] = MethodMetadata{
1, __hostFunction_NativeSampleTurboModuleSpecJSI_promiseAssert};
methodMap_["getConstants"] = MethodMetadata{
0, __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants};
}
std::shared_ptr<TurboModule> SampleTurboModuleSpec_ModuleProvider(
const std::string& moduleName,
const JavaTurboModule::InitParams& params) {
if (moduleName == "SampleTurboModule") {
return std::make_shared<NativeSampleTurboModuleSpecJSI>(params);
}
return nullptr;
}
} // namespace facebook::react

View File

@@ -0,0 +1,30 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// NOTE: This entire file should be codegen'ed.
#pragma once
#include <ReactCommon/JavaTurboModule.h>
#include <ReactCommon/TurboModule.h>
#include <fbjni/fbjni.h>
namespace facebook::react {
/**
* C++ class for module 'SampleTurboModule'
*/
class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public JavaTurboModule {
public:
NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams& params);
};
std::shared_ptr<TurboModule> SampleTurboModuleSpec_ModuleProvider(
const std::string& moduleName,
const JavaTurboModule::InitParams& params);
} // namespace facebook::react

View File

@@ -0,0 +1,246 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.fbreact.specs;
import android.app.Activity;
import android.util.DisplayMetrics;
import android.widget.Toast;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
@ReactModule(name = SampleLegacyModule.NAME)
public class SampleLegacyModule extends ReactContextBaseJavaModule {
public static final String NAME = "SampleLegacyModule";
private static final String TAG = SampleLegacyModule.class.getName();
private final ReactApplicationContext mContext;
private Toast mToast;
public SampleLegacyModule(ReactApplicationContext context) {
super(context);
mContext = context;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean getBool(boolean arg) {
log("getBool", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public double getEnum(double arg) {
log("getEnum", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public double getDouble(double arg) {
log("getDouble", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public int getInt(int arg) {
log("getInt", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public float getFloat(float arg) {
log("getFloat", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public double getObjectDouble(Double arg) {
log("getObjectDouble", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public Integer getObjectInteger(Integer arg) {
log("getObjectInteger", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public Float getObjectFloat(Float arg) {
log("getObjectFloat", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public String getString(String arg) {
log("getString", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public double getRootTag(double arg) {
log("getRootTag", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod
public void voidFunc() {
log("voidFunc", "<void>", "<void>");
return;
}
// This function returns {@link WritableMap} instead of {@link Map} for backward compat with
// existing native modules that use this Writable* as return types or in events. {@link
// WritableMap} is modified in the Java side, and read (or consumed) on the C++ side.
// In the future, all native modules should ideally return an immutable Map
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableMap getObject(ReadableMap arg) {
WritableNativeMap map = new WritableNativeMap();
map.merge(arg);
log("getObject", arg, map);
return map;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableMap getUnsafeObject(ReadableMap arg) {
WritableNativeMap map = new WritableNativeMap();
map.merge(arg);
log("getUnsafeObject", arg, map);
return map;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableMap getValue(double numberArg, String stringArg, ReadableMap mapArg) {
WritableMap map = new WritableNativeMap();
map.putDouble("x", numberArg);
map.putString("y", stringArg);
WritableMap zMap = new WritableNativeMap();
zMap.merge(mapArg);
map.putMap("z", zMap);
log(
"getValue",
MapBuilder.of("1-numberArg", numberArg, "2-stringArg", stringArg, "3-mapArg", mapArg),
map);
return map;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod
public void getValueWithCallback(final Callback callback) {
String result = "Value From Callback";
log("Callback", "Return Time", result);
callback.invoke(result);
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableArray getArray(ReadableArray arg) {
if (arg == null || Arguments.toList(arg) == null) {
// Returning an empty array, since the super class always returns non-null
return new WritableNativeArray();
}
WritableArray result = Arguments.makeNativeArray(Arguments.toList(arg));
log("getArray", arg, result);
return result;
}
@DoNotStrip
@SuppressWarnings("unused")
@ReactMethod
public void getValueWithPromise(boolean error, Promise promise) {
if (error) {
promise.reject(
"code 1",
"intentional promise rejection",
new Throwable("promise intentionally rejected"));
} else {
promise.resolve("result");
}
}
@Override
public final @Nullable Map<String, Object> getConstants() {
Map<String, Object> result = new HashMap<>();
DisplayMetrics displayMetrics = new DisplayMetrics();
Activity activity = mContext.getCurrentActivity();
if (activity != null) {
result.put("const2", 390);
}
result.put("const1", true);
result.put("const3", "something");
log("constantsToExport", "", result);
return result;
}
private void log(String method, Object input, Object output) {
if (mToast != null) {
mToast.cancel();
}
StringBuilder message = new StringBuilder("Method :");
message
.append(method)
.append("\nInputs: ")
.append(input.toString())
.append("\nOutputs: ")
.append(output.toString());
mToast = Toast.makeText(mContext, message.toString(), Toast.LENGTH_LONG);
mToast.show();
}
public void invalidate() {}
@Override
public String getName() {
return NAME;
}
}

View File

@@ -0,0 +1,248 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.fbreact.specs;
import android.app.Activity;
import android.util.DisplayMetrics;
import android.widget.Toast;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import java.util.HashMap;
import java.util.Map;
@ReactModule(name = SampleTurboModule.NAME)
public class SampleTurboModule extends NativeSampleTurboModuleSpec {
public static final String NAME = "SampleTurboModule";
private static final String TAG = SampleTurboModule.class.getName();
private final ReactApplicationContext mContext;
private Toast mToast;
public SampleTurboModule(ReactApplicationContext context) {
super(context);
mContext = context;
}
@DoNotStrip
@SuppressWarnings("unused")
@Override
public boolean getBool(boolean arg) {
log("getBool", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@Override
public double getEnum(double arg) {
log("getEnum", arg, arg);
return arg;
}
@Override
protected Map<String, Object> getTypedExportedConstants() {
Map<String, Object> result = new HashMap<>();
DisplayMetrics displayMetrics = new DisplayMetrics();
Activity activity = mContext.getCurrentActivity();
if (activity != null) {
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
result.put("const2", displayMetrics.widthPixels);
}
result.put("const1", true);
result.put("const3", "something");
log("constantsToExport", "", result);
return result;
}
@DoNotStrip
@SuppressWarnings("unused")
@Override
public double getNumber(double arg) {
log("getNumber", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@Override
public String getString(String arg) {
log("getString", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@Override
public double getRootTag(double arg) {
log("getRootTag", arg, arg);
return arg;
}
@DoNotStrip
@SuppressWarnings("unused")
@Override
public void voidFunc() {
log("voidFunc", "<void>", "<void>");
return;
}
// This function returns {@link WritableMap} instead of {@link Map} for backward compat with
// existing native modules that use this Writable* as return types or in events. {@link
// WritableMap} is modified in the Java side, and read (or consumed) on the C++ side.
// In the future, all native modules should ideally return an immutable Map
@DoNotStrip
@Override
@SuppressWarnings("unused")
public WritableMap getObject(ReadableMap arg) {
WritableNativeMap map = new WritableNativeMap();
map.merge(arg);
log("getObject", arg, map);
return map;
}
@DoNotStrip
@Override
@SuppressWarnings("unused")
public WritableMap getUnsafeObject(ReadableMap arg) {
WritableNativeMap map = new WritableNativeMap();
map.merge(arg);
log("getUnsafeObject", arg, map);
return map;
}
@DoNotStrip
@SuppressWarnings("unused")
@Override
public WritableMap getValue(double numberArg, String stringArg, ReadableMap mapArg) {
WritableMap map = new WritableNativeMap();
map.putDouble("x", numberArg);
map.putString("y", stringArg);
WritableMap zMap = new WritableNativeMap();
zMap.merge(mapArg);
map.putMap("z", zMap);
log(
"getValue",
MapBuilder.of("1-numberArg", numberArg, "2-stringArg", stringArg, "3-mapArg", mapArg),
map);
return map;
}
@DoNotStrip
@SuppressWarnings("unused")
@Override
public void getValueWithCallback(final Callback callback) {
String result = "Value From Callback";
log("Callback", "Return Time", result);
callback.invoke(result);
}
@DoNotStrip
@SuppressWarnings("unused")
@Override
public WritableArray getArray(ReadableArray arg) {
if (arg == null || Arguments.toList(arg) == null) {
// Returning an empty array, since the super class always returns non-null
return new WritableNativeArray();
}
WritableArray result = Arguments.makeNativeArray(Arguments.toList(arg));
log("getArray", arg, result);
return result;
}
@Override
@DoNotStrip
@SuppressWarnings("unused")
public void getValueWithPromise(boolean error, Promise promise) {
if (error) {
promise.reject(
"code 1",
"intentional promise rejection",
new Throwable("promise intentionally rejected"));
} else {
promise.resolve("result");
}
}
@Override
@DoNotStrip
@SuppressWarnings("unused")
public void voidFuncThrows() {
throw new RuntimeException("Intentional exception from JVM voidFuncThrows");
};
@Override
@DoNotStrip
@SuppressWarnings("unused")
public WritableMap getObjectThrows(ReadableMap arg) {
throw new RuntimeException(
"Intentional exception from JVM getObjectThrows with " + arg.toString());
};
@Override
@DoNotStrip
@SuppressWarnings("unused")
public void promiseThrows(Promise promise) {
throw new RuntimeException("Intentional exception from JVM promiseThrows");
};
@Override
@DoNotStrip
@SuppressWarnings("unused")
public void voidFuncAssert() {
assert false : "Intentional assert from JVM voidFuncAssert";
};
@Override
@DoNotStrip
@SuppressWarnings("unused")
public WritableMap getObjectAssert(ReadableMap arg) {
assert false : "Intentional assert from JVM getObjectAssert with " + arg.toString();
return null;
};
@Override
@DoNotStrip
@SuppressWarnings("unused")
public void promiseAssert(Promise promise) {
assert false : "Intentional assert from JVM promiseAssert";
};
private void log(String method, Object input, Object output) {
if (mToast != null) {
mToast.cancel();
}
StringBuilder message = new StringBuilder("Method :");
message
.append(method)
.append("\nInputs: ")
.append(input.toString())
.append("\nOutputs: ")
.append(output.toString());
mToast = Toast.makeText(mContext, message.toString(), Toast.LENGTH_LONG);
mToast.show();
}
public void invalidate() {}
@Override
public String getName() {
return NAME;
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// NOTE: This entire file should be codegen'ed.
#import <vector>
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <ReactCommon/RCTTurboModule.h>
/**
* The ObjC protocol based on the JS Flow type for SampleTurboModule.
*/
@protocol NativeSampleTurboModuleSpec <RCTBridgeModule, RCTTurboModule>
- (void)voidFunc;
- (NSNumber *)getBool:(BOOL)arg;
- (NSNumber *)getEnum:(double)arg;
- (NSNumber *)getNumber:(double)arg;
- (NSString *)getString:(NSString *)arg;
- (NSArray<id<NSObject>> *)getArray:(NSArray *)arg;
- (NSDictionary *)getObject:(NSDictionary *)arg;
- (NSDictionary *)getUnsafeObject:(NSDictionary *)arg;
- (NSNumber *)getRootTag:(double)arg;
- (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)voidFuncThrows;
- (NSDictionary *)getObjectThrows:(NSDictionary *)arg;
- (void)promiseThrows:(BOOL)error resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
- (void)voidFuncAssert;
- (NSDictionary *)getObjectAssert:(NSDictionary *)arg;
- (void)promiseAssert:(BOOL)error resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
- (NSDictionary *)constantsToExport;
- (NSDictionary *)getConstants;
@end
namespace facebook::react {
/**
* The iOS TurboModule impl specific to SampleTurboModule.
*/
class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public ObjCTurboModule {
public:
NativeSampleTurboModuleSpecJSI(const ObjCTurboModule::InitParams &params);
};
} // namespace facebook::react

View File

@@ -0,0 +1,229 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTNativeSampleTurboModuleSpec.h"
namespace facebook::react {
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)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, BooleanKind, "getBool", @selector(getBool:), args, count);
}
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getEnum(
facebook::jsi::Runtime &rt,
TurboModule &turboModule,
const facebook::jsi::Value *args,
size_t count)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, NumberKind, "getEnum", @selector(getEnum:), args, 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)
{
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)
{
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)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, ObjectKind, "getObject", @selector(getObject:), args, count);
}
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getUnsafeObject(
facebook::jsi::Runtime &rt,
TurboModule &turboModule,
const facebook::jsi::Value *args,
size_t count)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, ObjectKind, "getUnsafeObject", @selector(getUnsafeObject:), args, count);
}
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getRootTag(
facebook::jsi::Runtime &rt,
TurboModule &turboModule,
const facebook::jsi::Value *args,
size_t count)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, NumberKind, "getRootTag", @selector(getRootTag:), args, 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)
{
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)
{
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)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, ObjectKind, "getConstants", @selector(getConstants), args, count);
}
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncThrows(
facebook::jsi::Runtime &rt,
TurboModule &turboModule,
const facebook::jsi::Value *args,
size_t count)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, VoidKind, "voidFuncThrows", @selector(voidFuncThrows), args, count);
}
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getObjectThrows(
facebook::jsi::Runtime &rt,
TurboModule &turboModule,
const facebook::jsi::Value *args,
size_t count)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, ObjectKind, "getObjectThrows", @selector(getObjectThrows:), args, count);
}
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_promiseThrows(
facebook::jsi::Runtime &rt,
TurboModule &turboModule,
const facebook::jsi::Value *args,
size_t count)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, PromiseKind, "promiseThrows", @selector(promiseThrows:resolve:reject:), args, count);
}
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncAssert(
facebook::jsi::Runtime &rt,
TurboModule &turboModule,
const facebook::jsi::Value *args,
size_t count)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, VoidKind, "voidFuncAssert", @selector(voidFuncAssert), args, count);
}
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getObjectAssert(
facebook::jsi::Runtime &rt,
TurboModule &turboModule,
const facebook::jsi::Value *args,
size_t count)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, ObjectKind, "getObjectAssert", @selector(getObjectAssert:), args, count);
}
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_promiseAssert(
facebook::jsi::Runtime &rt,
TurboModule &turboModule,
const facebook::jsi::Value *args,
size_t count)
{
return static_cast<ObjCTurboModule &>(turboModule)
.invokeObjCMethod(rt, PromiseKind, "promiseAssert", @selector(promiseAssert:resolve:reject:), args, count);
}
NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const ObjCTurboModule::InitParams &params)
: ObjCTurboModule(params)
{
methodMap_["voidFunc"] = MethodMetadata{0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc};
methodMap_["getBool"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getBool};
methodMap_["getEnum"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getEnum};
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_["getUnsafeObject"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getUnsafeObject};
methodMap_["getRootTag"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getRootTag};
methodMap_["getValue"] = MethodMetadata{3, __hostFunction_NativeSampleTurboModuleSpecJSI_getValue};
methodMap_["getValueWithCallback"] =
MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback};
methodMap_["getValueWithPromise"] =
MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise};
methodMap_["voidFuncThrows"] = MethodMetadata{0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncThrows};
methodMap_["getObjectThrows"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getObjectThrows};
methodMap_["promiseThrows"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_promiseThrows};
methodMap_["voidFuncAssert"] = MethodMetadata{0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncAssert};
methodMap_["getObjectAssert"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getObjectAssert};
methodMap_["promiseAssert"] = MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_promiseAssert};
methodMap_["getConstants"] = MethodMetadata{0, __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants};
}
} // namespace facebook::react

View File

@@ -0,0 +1,16 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <React/RCTAssert.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTInvalidating.h>
#import <React/RCTUtils.h>
@interface RCTSampleLegacyModule : NSObject <RCTBridgeModule, RCTInvalidating>
@end

View File

@@ -0,0 +1,222 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTSampleLegacyModule.h"
@implementation RCTSampleLegacyModule {
RCTBridge *_bridge;
}
// Backward-compatible export
RCT_EXPORT_MODULE()
// Backward-compatible queue configuration
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (void)setBridge:(RCTBridge *)bridge
{
_bridge = bridge;
}
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}
// Backward compatible invalidation
- (void)invalidate
{
// Actually do nothing here.
NSLog(@"Invalidating RCTSampleTurboModule...");
}
- (NSDictionary *)getConstants
{
__block NSDictionary *constants;
RCTUnsafeExecuteOnMainQueueSync(^{
constants = @{
@"const1" : @YES,
@"const2" : @(390),
@"const3" : @"something",
};
});
return constants;
}
// TODO: Remove once fully migrated to TurboModule.
- (NSDictionary *)constantsToExport
{
return [self getConstants];
}
RCT_EXPORT_METHOD(voidFunc)
{
// Nothing to do
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getBool : (BOOL)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getEnum : (double)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getNumber : (double)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getFloat : (float)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getInt : (int)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getLongLong : (int64_t)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getUnsignedLongLong : (uint64_t)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getNSInteger : (NSInteger)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getNSUInteger : (NSUInteger)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSArray<id<NSObject>> *, getArray : (NSArray *)arg)
{
return arg;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getObject : (NSDictionary *)arg)
{
return arg;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getString : (NSString *)arg)
{
return arg;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getNSNumber : (nonnull NSNumber *)arg)
{
return arg;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getUnsafeObject : (NSDictionary *)arg)
{
return arg;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getRootTag : (double)arg)
{
return @(arg);
}
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],
};
}
RCT_EXPORT_METHOD(getValueWithCallback : (RCTResponseSenderBlock)callback)
{
if (!callback) {
return;
}
callback(@[ @"value from callback!" ]);
}
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]);
} else {
resolve(@"result!");
}
}
RCT_EXPORT_METHOD(voidFuncThrows)
{
NSException *myException = [NSException exceptionWithName:@"Excepption"
reason:@"Intentional exception from ObjC voidFuncThrows"
userInfo:nil];
@throw myException;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getObjectThrows : (NSDictionary *)arg)
{
NSException *myException = [NSException exceptionWithName:@"Excepption"
reason:@"Intentional exception from ObjC getObjectThrows"
userInfo:nil];
@throw myException;
}
RCT_EXPORT_METHOD(promiseThrows
: (BOOL)error resolve
: (RCTPromiseResolveBlock)resolve reject
: (RCTPromiseRejectBlock)reject)
{
NSException *myException = [NSException exceptionWithName:@"Excepption"
reason:@"Intentional exception from ObjC promiseThrows"
userInfo:nil];
@throw myException;
}
RCT_EXPORT_METHOD(voidFuncAssert)
{
RCTAssert(false, @"Intentional assert from ObjC voidFuncAssert");
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getObjectAssert : (NSDictionary *)arg)
{
RCTAssert(false, @"Intentional assert from ObjC getObjectAssert");
return arg;
}
RCT_EXPORT_METHOD(promiseAssert
: (BOOL)error resolve
: (RCTPromiseResolveBlock)resolve reject
: (RCTPromiseRejectBlock)reject)
{
RCTAssert(false, @"Intentional assert from ObjC promiseAssert");
}
@end

View File

@@ -0,0 +1,27 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#import <React/RCTCxxModule.h>
#import <ReactCommon/RCTTurboModule.h>
/**
* Sample backward-compatible RCTCxxModule-based module.
* With jsi::HostObject, this class is no longer necessary, but the system supports it for
* backward compatibility.
*/
@interface RCTSampleTurboCxxModule_v1 : RCTCxxModule <RCTTurboModule>
@end
/**
* Second variant of a sample backward-compatible RCTCxxModule-based module.
*/
@interface RCTSampleTurboCxxModule_v2 : RCTCxxModule <RCTTurboModule>
@end

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTSampleTurboCxxModule.h"
#import <ReactCommon/SampleTurboCxxModule.h>
#import <cxxreact/CxxModule.h>
#import "SampleTurboCxxModuleLegacyImpl.h"
using namespace facebook;
// ObjC++ wrapper.
@implementation RCTSampleTurboCxxModule_v1
RCT_EXPORT_MODULE();
- (std::shared_ptr<react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<react::CallInvoker>)jsInvoker
{
return std::make_shared<react::SampleTurboCxxModule>(jsInvoker);
}
- (std::unique_ptr<xplat::module::CxxModule>)createModule
{
return nullptr;
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return nullptr;
}
@end
@implementation RCTSampleTurboCxxModule_v2
RCT_EXPORT_MODULE();
- (std::unique_ptr<xplat::module::CxxModule>)createModule
{
return std::make_unique<react::SampleTurboCxxModuleLegacyImpl>();
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return nullptr;
}
@end

View File

@@ -0,0 +1,18 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
#import "RCTNativeSampleTurboModuleSpec.h"
/**
* 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>
@end

View File

@@ -0,0 +1,195 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTSampleTurboModule.h"
#import <React/RCTAssert.h>
#import <React/RCTUtils.h>
#import <UIKit/UIKit.h>
using namespace facebook::react;
@implementation RCTSampleTurboModule
// Backward-compatible export
RCT_EXPORT_MODULE()
// Backward-compatible queue configuration
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<NativeSampleTurboModuleSpecJSI>(params);
}
// Backward compatible invalidation
- (void)invalidate
{
// Actually do nothing here.
NSLog(@"Invalidating RCTSampleTurboModule...");
}
- (NSDictionary *)getConstants
{
__block NSDictionary *constants;
RCTUnsafeExecuteOnMainQueueSync(^{
UIScreen *mainScreen = UIScreen.mainScreen;
CGSize screenSize = mainScreen.bounds.size;
constants = @{
@"const1" : @YES,
@"const2" : @(screenSize.width),
@"const3" : @"something",
};
});
return constants;
}
// TODO: Remove once fully migrated to TurboModule.
- (NSDictionary *)constantsToExport
{
return [self getConstants];
}
RCT_EXPORT_METHOD(voidFunc)
{
// Nothing to do
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getBool : (BOOL)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getEnum : (double)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getNumber : (double)arg)
{
return @(arg);
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getString : (NSString *)arg)
{
return arg;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSArray<id<NSObject>> *, getArray : (NSArray *)arg)
{
return arg;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getObject : (NSDictionary *)arg)
{
return arg;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getUnsafeObject : (NSDictionary *)arg)
{
return arg;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getRootTag : (double)arg)
{
return @(arg);
}
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],
};
}
RCT_EXPORT_METHOD(getValueWithCallback : (RCTResponseSenderBlock)callback)
{
if (!callback) {
return;
}
callback(@[ @"value from callback!" ]);
}
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]);
} else {
resolve(@"result!");
}
}
RCT_EXPORT_METHOD(voidFuncThrows)
{
NSException *myException = [NSException exceptionWithName:@"Excepption"
reason:@"Intentional exception from ObjC voidFuncThrows"
userInfo:nil];
@throw myException;
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getObjectThrows : (NSDictionary *)arg)
{
NSException *myException = [NSException exceptionWithName:@"Excepption"
reason:@"Intentional exception from ObjC getObjectThrows"
userInfo:nil];
@throw myException;
}
RCT_EXPORT_METHOD(promiseThrows
: (BOOL)error resolve
: (RCTPromiseResolveBlock)resolve reject
: (RCTPromiseRejectBlock)reject)
{
NSException *myException = [NSException exceptionWithName:@"Excepption"
reason:@"Intentional exception from ObjC promiseThrows"
userInfo:nil];
@throw myException;
}
RCT_EXPORT_METHOD(voidFuncAssert)
{
RCTAssert(false, @"Intentional assert from ObjC voidFuncAssert");
}
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getObjectAssert : (NSDictionary *)arg)
{
RCTAssert(false, @"Intentional assert from ObjC getObjectAssert");
return arg;
}
RCT_EXPORT_METHOD(promiseAssert
: (BOOL)error resolve
: (RCTPromiseResolveBlock)resolve reject
: (RCTPromiseRejectBlock)reject)
{
RCTAssert(false, @"Intentional assert from ObjC promiseAssert");
}
@end

View File

@@ -0,0 +1,177 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "SampleTurboCxxModuleLegacyImpl.h"
#include <cxxreact/JsArgumentHelpers.h>
using namespace facebook::xplat::module;
namespace facebook::react {
SampleTurboCxxModuleLegacyImpl::SampleTurboCxxModuleLegacyImpl() {}
std::string SampleTurboCxxModuleLegacyImpl::getName() {
return "SampleTurboCxxModule_v2";
}
std::map<std::string, folly::dynamic>
SampleTurboCxxModuleLegacyImpl::getConstants() {
return {
{"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(
"getEnum",
[this](folly::dynamic args) {
return getEnum(xplat::jsArgAsDouble(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(
"getUnsafeObject",
[this](folly::dynamic args) {
return getUnsafeObject(xplat::jsArgAsObject(args, 0));
},
CxxModule::SyncTag),
CxxModule::Method(
"getRootTag",
[this](folly::dynamic args) {
return getNumber(xplat::jsArgAsDouble(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);
}),
};
};
void SampleTurboCxxModuleLegacyImpl::voidFunc() {
// Do nothing.
}
bool SampleTurboCxxModuleLegacyImpl::getBool(bool arg) {
return arg;
}
double SampleTurboCxxModuleLegacyImpl::getEnum(double arg) {
return arg;
}
double SampleTurboCxxModuleLegacyImpl::getNumber(double arg) {
return arg;
}
std::string SampleTurboCxxModuleLegacyImpl::getString(const std::string& arg) {
return arg;
}
folly::dynamic SampleTurboCxxModuleLegacyImpl::getArray(
const folly::dynamic& arg) {
return arg;
}
folly::dynamic SampleTurboCxxModuleLegacyImpl::getObject(
const folly::dynamic& arg) {
return arg;
}
folly::dynamic SampleTurboCxxModuleLegacyImpl::getUnsafeObject(
const folly::dynamic& arg) {
return arg;
}
double SampleTurboCxxModuleLegacyImpl::getRootTag(double 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);
}
void SampleTurboCxxModuleLegacyImpl::getValueWithCallback(
const CxxModule::Callback& callback) {
callback({"value from callback!"});
}
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")});
}
}
} // namespace facebook::react

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <cxxreact/CxxModule.h>
namespace facebook::react {
/**
* A sample CxxModule (legacy system) implementation.
*/
class SampleTurboCxxModuleLegacyImpl
: public facebook::xplat::module::CxxModule {
public:
SampleTurboCxxModuleLegacyImpl();
std::string getName() override;
std::map<std::string, folly::dynamic> getConstants() override;
std::vector<facebook::xplat::module::CxxModule::Method> getMethods() override;
// API
void voidFunc();
bool getBool(bool arg);
double getEnum(double arg);
double getNumber(double arg);
std::string getString(const std::string& arg);
folly::dynamic getArray(const folly::dynamic& arg);
folly::dynamic getObject(const folly::dynamic& arg);
folly::dynamic getUnsafeObject(const folly::dynamic& arg);
double getRootTag(double 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);
};
} // namespace facebook::react