first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
# 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)
include(${REACT_COMMON_DIR}/cmake-utils/react-native-flags.cmake)
add_library(callinvoker INTERFACE)
target_include_directories(callinvoker INTERFACE .)
target_compile_reactnative_options(callinvoker INTERFACE)
target_compile_options(callinvoker INTERFACE -Wpedantic)

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.
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
Pod::Spec.new do |s|
s.name = "React-callinvoker"
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.source_files = podspec_sources("**/*.{cpp,h}", "**/*.h")
s.header_dir = "ReactCommon"
end

View File

@@ -0,0 +1,61 @@
/*
* 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 "SchedulerPriority.h"
#include <functional>
#include <string>
namespace facebook::jsi {
class Runtime;
}
namespace facebook::react {
using CallFunc = std::function<void(jsi::Runtime &)>;
/**
* An interface for a generic native-to-JS call invoker. See BridgeJSCallInvoker
* for an implementation.
*/
class CallInvoker {
public:
virtual void invokeAsync(CallFunc &&func) noexcept = 0;
virtual void invokeAsync(SchedulerPriority /*priority*/, CallFunc &&func) noexcept
{
// When call with priority is not implemented, fall back to a regular async
// execution
invokeAsync(std::move(func));
}
virtual void invokeSync(CallFunc &&func) = 0;
// Backward compatibility only, prefer the CallFunc methods instead
virtual void invokeAsync(std::function<void()> &&func) noexcept
{
invokeAsync([func = std::move(func)](jsi::Runtime &) { func(); });
}
virtual void invokeSync(std::function<void()> &&func)
{
invokeSync([func = std::move(func)](jsi::Runtime &) { func(); });
}
virtual ~CallInvoker() = default;
};
using NativeMethodCallFunc = std::function<void()>;
class NativeMethodCallInvoker {
public:
virtual void invokeAsync(const std::string &methodName, NativeMethodCallFunc &&func) noexcept = 0;
virtual void invokeSync(const std::string &methodName, NativeMethodCallFunc &&func) = 0;
virtual ~NativeMethodCallInvoker() = default;
};
} // namespace facebook::react

View File

@@ -0,0 +1,20 @@
/*
* 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
namespace facebook::react {
enum class SchedulerPriority : int {
ImmediatePriority = 1,
UserBlockingPriority = 2,
NormalPriority = 3,
LowPriority = 4,
IdlePriority = 5,
};
} // namespace facebook::react

View File

@@ -0,0 +1,49 @@
/*
* 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 <ReactCommon/CallInvoker.h>
#include <jsi/jsi.h>
#include <list>
namespace facebook::react {
class TestCallInvoker : public CallInvoker {
public:
explicit TestCallInvoker(facebook::jsi::Runtime &runtime) : runtime_(runtime) {}
void invokeAsync(CallFunc &&func) noexcept override
{
queue_.push_back(std::move(func));
}
void invokeSync(CallFunc &&func) override
{
func(runtime_);
}
void flushQueue()
{
while (!queue_.empty()) {
queue_.front()(runtime_);
queue_.pop_front();
runtime_.drainMicrotasks(); // Run microtasks every cycle.
}
}
size_t queueSize()
{
return queue_.size();
}
private:
facebook::jsi::Runtime &runtime_;
std::list<CallFunc> queue_{};
};
} // namespace facebook::react