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,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.
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)
include(${REACT_COMMON_DIR}/cmake-utils/react-native-flags.cmake)
file(GLOB rrc_root_SRC CONFIGURE_DEPENDS *.cpp)
add_library(rrc_root OBJECT ${rrc_root_SRC})
target_include_directories(rrc_root PUBLIC ${REACT_COMMON_DIR})
target_link_libraries(rrc_root
folly_runtime
glog
glog_init
react_debug
react_renderer_core
react_renderer_debug
react_renderer_graphics
rrc_view
yoga
)
target_compile_reactnative_options(rrc_root PRIVATE)
target_compile_options(rrc_root PRIVATE -Wpedantic)

View File

@@ -0,0 +1,17 @@
/*
* 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/components/root/RootShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h>
namespace facebook::react {
using RootComponentDescriptor = ConcreteComponentDescriptor<RootShadowNode>;
} // namespace facebook::react

View File

@@ -0,0 +1,36 @@
/*
* 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 "RootProps.h"
#include <react/renderer/components/view/YogaLayoutableShadowNode.h>
#include <react/renderer/components/view/conversions.h>
namespace facebook::react {
// Note that a default/empty context may be passed here from RootShadowNode.
// If that's a problem and the context is necessary here, refactor
// RootShadowNode first.
RootProps::RootProps(
const PropsParserContext& context,
const RootProps& sourceProps,
const RawProps& rawProps)
: ViewProps(context, sourceProps, rawProps) {}
// Note that a default/empty context may be passed here from RootShadowNode.
// If that's a problem and the context is necessary here, refactor
// RootShadowNode first.
RootProps::RootProps(
const PropsParserContext& /*context*/,
const RootProps& /*sourceProps*/,
const LayoutConstraints& layoutConstraints,
const LayoutContext& layoutContext)
: ViewProps(),
layoutConstraints(layoutConstraints),
layoutContext(layoutContext) {};
} // namespace facebook::react

View File

@@ -0,0 +1,35 @@
/*
* 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 <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/LayoutConstraints.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/core/PropsParserContext.h>
namespace facebook::react {
class RootProps final : public ViewProps {
public:
RootProps() = default;
RootProps(const PropsParserContext &context, const RootProps &sourceProps, const RawProps &rawProps);
RootProps(
const PropsParserContext &context,
const RootProps &sourceProps,
const LayoutConstraints &layoutConstraints,
const LayoutContext &layoutContext);
#pragma mark - Props
LayoutConstraints layoutConstraints{};
LayoutContext layoutContext{};
};
} // namespace facebook::react

View File

@@ -0,0 +1,65 @@
/*
* 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 "RootShadowNode.h"
#include <cxxreact/TraceSection.h>
#include <react/renderer/components/view/conversions.h>
namespace facebook::react {
// NOLINTNEXTLINE(facebook-hte-CArray,modernize-avoid-c-arrays)
const char RootComponentName[] = "RootView";
bool RootShadowNode::layoutIfNeeded(
std::vector<const LayoutableShadowNode*>* affectedNodes) {
TraceSection s("RootShadowNode::layout");
if (getIsLayoutClean()) {
return false;
}
ensureUnsealed();
auto layoutContext = getConcreteProps().layoutContext;
layoutContext.affectedNodes = affectedNodes;
layoutTree(layoutContext, getConcreteProps().layoutConstraints);
return true;
}
Transform RootShadowNode::getTransform() const {
auto viewportOffset = getConcreteProps().layoutContext.viewportOffset;
return Transform::Translate(viewportOffset.x, viewportOffset.y, 0);
}
RootShadowNode::Unshared RootShadowNode::clone(
const PropsParserContext& propsParserContext,
const LayoutConstraints& layoutConstraints,
const LayoutContext& layoutContext) const {
auto props = std::make_shared<const RootProps>(
propsParserContext, getConcreteProps(), layoutConstraints, layoutContext);
auto newRootShadowNode = std::make_shared<RootShadowNode>(
*this,
ShadowNodeFragment{
/* .props = */ props,
});
if (layoutConstraints != getConcreteProps().layoutConstraints) {
newRootShadowNode->dirtyLayout();
}
return newRootShadowNode;
}
void RootShadowNode::setInstanceHandle(
InstanceHandle::Shared instanceHandle) const {
getFamily().setInstanceHandle(instanceHandle);
}
} // namespace facebook::react

View File

@@ -0,0 +1,62 @@
/*
* 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 <react/renderer/components/root/RootProps.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/core/PropsParserContext.h>
namespace facebook::react {
class RootShadowNode;
extern const char RootComponentName[];
/*
* `ShadowNode` for the root component.
* Besides all functionality of the `View` component, `RootShadowNode` contains
* props which represent external layout constraints and context of the
* shadow tree.
*/
class RootShadowNode final : public ConcreteViewShadowNode<RootComponentName, RootProps> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;
using Shared = std::shared_ptr<const RootShadowNode>;
using Unshared = std::shared_ptr<RootShadowNode>;
static ShadowNodeTraits BaseTraits()
{
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::RootNodeKind);
return traits;
}
/*
* Layouts the shadow tree if needed.
* Returns `false` if the three is already laid out.
*/
bool layoutIfNeeded(std::vector<const LayoutableShadowNode *> *affectedNodes = {});
/*
* Clones the node with given `layoutConstraints` and `layoutContext`.
*/
RootShadowNode::Unshared clone(
const PropsParserContext &propsParserContext,
const LayoutConstraints &layoutConstraints,
const LayoutContext &layoutContext) const;
Transform getTransform() const override;
void setInstanceHandle(InstanceHandle::Shared instanceHandle) const;
};
} // 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.
*/
#include <react/renderer/components/root/RootComponentDescriptor.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/element/ComponentBuilder.h>
#include <gtest/gtest.h>
#include <react/renderer/element/Element.h>
#include <react/renderer/element/testUtils.h>
namespace facebook::react {
TEST(RootShadowNodeTest, cloneWithLayoutConstraints) {
ContextContainer contextContainer{};
PropsParserContext parserContext{-1, contextContainer};
auto builder = simpleComponentBuilder();
std::shared_ptr<RootShadowNode> rootShadowNode;
LayoutConstraints defaultLayoutConstraints = {};
auto element =
Element<RootShadowNode>().reference(rootShadowNode).tag(1).props([&] {
auto sharedProps = std::make_shared<RootProps>();
sharedProps->layoutConstraints = defaultLayoutConstraints;
return sharedProps;
});
builder.build(element);
EXPECT_FALSE(rootShadowNode->getIsLayoutClean());
EXPECT_TRUE(rootShadowNode->layoutIfNeeded());
EXPECT_TRUE(rootShadowNode->getIsLayoutClean());
auto clonedWithDifferentLayoutConstraints = rootShadowNode->clone(
parserContext, LayoutConstraints{{0, 0}, {10, 10}}, {});
EXPECT_FALSE(clonedWithDifferentLayoutConstraints->getIsLayoutClean());
EXPECT_TRUE(clonedWithDifferentLayoutConstraints->layoutIfNeeded());
}
} // namespace facebook::react