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,29 @@
# 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)
file(GLOB react_nativemodule_fantomspecificmethods_SRC CONFIGURE_DEPENDS *.cpp internal/*.cpp)
add_library(react_nativemodule_fantomspecificmethods OBJECT ${react_nativemodule_fantomspecificmethods_SRC})
target_include_directories(react_nativemodule_fantomspecificmethods PUBLIC ${REACT_COMMON_DIR})
target_include_directories(react_nativemodule_fantomspecificmethods PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/internal)
target_link_libraries(react_nativemodule_fantomspecificmethods
react_codegen_rncore
react_cxxreact
react_renderer_bridging
react_renderer_core
react_renderer_graphics
react_renderer_observers_intersection
react_renderer_runtimescheduler
react_renderer_uimanager
rrc_view
)
target_compile_reactnative_options(react_nativemodule_fantomspecificmethods PRIVATE)
target_compile_options(react_nativemodule_fantomspecificmethods PRIVATE -Wpedantic -Wno-deprecated-declarations)

View File

@@ -0,0 +1,52 @@
/*
* 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 "NativeFantomTestSpecificMethods.h"
#include <react/renderer/uimanager/UIManager.h>
#include <react/renderer/uimanager/UIManagerBinding.h>
#include "internal/FantomForcedCloneCommitHook.h"
#if RN_DISABLE_OSS_PLUGIN_HEADER
#include "Plugins.h"
#endif
std::shared_ptr<facebook::react::TurboModule>
NativeFantomTestSpecificMethodsModuleProvider(
std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
return std::make_shared<facebook::react::NativeFantomTestSpecificMethods>(
std::move(jsInvoker));
}
namespace {
facebook::react::UIManager& getUIManagerFromRuntime(
facebook::jsi::Runtime& runtime) {
return facebook::react::UIManagerBinding::getBinding(runtime)->getUIManager();
}
} // namespace
namespace facebook::react {
NativeFantomTestSpecificMethods::NativeFantomTestSpecificMethods(
std::shared_ptr<CallInvoker> jsInvoker)
: NativeFantomTestSpecificMethodsCxxSpec(std::move(jsInvoker)),
fantomForcedCloneCommitHook_(
std::make_shared<FantomForcedCloneCommitHook>()) {}
void NativeFantomTestSpecificMethods::registerForcedCloneCommitHook(
jsi::Runtime& runtime) {
auto& uiManager = getUIManagerFromRuntime(runtime);
uiManager.registerCommitHook(*fantomForcedCloneCommitHook_);
}
void NativeFantomTestSpecificMethods::takeFunctionAndNoop(
jsi::Runtime& runtime,
jsi::Function function) {}
} // namespace facebook::react

View File

@@ -0,0 +1,28 @@
/*
* 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 <FBReactNativeSpec/FBReactNativeSpecJSI.h>
namespace facebook::react {
struct FantomForcedCloneCommitHook;
class NativeFantomTestSpecificMethods : public NativeFantomTestSpecificMethodsCxxSpec<NativeFantomTestSpecificMethods> {
public:
explicit NativeFantomTestSpecificMethods(std::shared_ptr<CallInvoker> jsInvoker);
void registerForcedCloneCommitHook(jsi::Runtime &runtime);
void takeFunctionAndNoop(jsi::Runtime &runtime, jsi::Function callback);
private:
std::shared_ptr<FantomForcedCloneCommitHook> fantomForcedCloneCommitHook_{};
};
} // namespace facebook::react

View File

@@ -0,0 +1,57 @@
/*
* 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 "FantomForcedCloneCommitHook.h"
#include <react/renderer/uimanager/UIManagerBinding.h>
#include <react/renderer/uimanager/primitives.h>
namespace facebook::react {
namespace {
std::shared_ptr<const ShadowNode> findAndClone(
const std::shared_ptr<const ShadowNode>& node) {
if (node->getProps()->nativeId == "to-be-cloned-in-the-commit-hook") {
return node->clone({});
}
auto children = node->getChildren();
for (int i = 0; i < children.size(); i++) {
auto& child = children[i];
auto maybeClone = findAndClone(child);
if (maybeClone != child) {
children[i] = maybeClone;
return node->clone(
{.props = ShadowNodeFragment::propsPlaceholder(),
.children =
std::make_shared<std::vector<std::shared_ptr<const ShadowNode>>>(
children)});
}
}
return node;
}
} // namespace
void FantomForcedCloneCommitHook::commitHookWasRegistered(
const UIManager& /*uiManager*/) noexcept {}
void FantomForcedCloneCommitHook::commitHookWasUnregistered(
const UIManager& /*uiManager*/) noexcept {}
RootShadowNode::Unshared FantomForcedCloneCommitHook::shadowTreeWillCommit(
const ShadowTree& /*shadowTree*/,
const std::shared_ptr<const RootShadowNode>& /*oldRootShadowNode*/,
const RootShadowNode::Unshared& newRootShadowNode) noexcept {
auto result = findAndClone(newRootShadowNode);
return std::static_pointer_cast<RootShadowNode>(
std::const_pointer_cast<ShadowNode>(result));
}
} // namespace facebook::react

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
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/uimanager/UIManager.h>
#include <react/renderer/uimanager/UIManagerCommitHook.h>
namespace facebook::react {
struct FantomForcedCloneCommitHook : public UIManagerCommitHook {
void commitHookWasRegistered(const UIManager & /*uiManager*/) noexcept override;
void commitHookWasUnregistered(const UIManager & /*uiManager*/) noexcept override;
RootShadowNode::Unshared shadowTreeWillCommit(
const ShadowTree &shadowTree,
const std::shared_ptr<const RootShadowNode> &oldRootShadowNode,
const RootShadowNode::Unshared &newRootShadowNode) noexcept override;
};
} // namespace facebook::react