Fabric: ShadowNode::Fragment

Summary:
@public
This diff changes a way how we specify a shape of newly created and/or cloned of ShadowNode. Previously we pass those values as a list of arguments, now those values are coupled into a new data structure called ShadowNodeFragment. All that makes suppose to make code much more easy to read and maintain, this is especially important because we want to add a couple of new entities in this set.

Reviewed By: mdvacca

Differential Revision: D8988389

fbshipit-source-id: 1835f646e1ecc6a1f413feaf1900f3d3ad0ebc05
This commit is contained in:
Valentin Shergin 2018-08-04 09:30:20 -07:00 committed by Facebook Github Bot
parent 682fd43f3b
commit 95074e6c12
7 changed files with 125 additions and 114 deletions

View File

@ -43,7 +43,6 @@ class ConcreteViewShadowNode:
static_assert(std::is_base_of<AccessibilityProps, ViewPropsT>::value, "ViewPropsT must be a descendant of AccessibilityProps"); static_assert(std::is_base_of<AccessibilityProps, ViewPropsT>::value, "ViewPropsT must be a descendant of AccessibilityProps");
public: public:
using ConcreteViewProps = ViewPropsT; using ConcreteViewProps = ViewPropsT;
using SharedConcreteViewProps = std::shared_ptr<const ViewPropsT>; using SharedConcreteViewProps = std::shared_ptr<const ViewPropsT>;
using ConcreteViewEventEmitter = ViewEventEmitterT; using ConcreteViewEventEmitter = ViewEventEmitterT;
@ -51,55 +50,43 @@ public:
using SharedConcreteViewShadowNode = std::shared_ptr<const ConcreteViewShadowNode>; using SharedConcreteViewShadowNode = std::shared_ptr<const ConcreteViewShadowNode>;
ConcreteViewShadowNode( ConcreteViewShadowNode(
const Tag &tag, const ShadowNodeFragment &fragment,
const Tag &rootTag,
const SharedConcreteViewProps &props,
const SharedConcreteViewEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children,
const ShadowNodeCloneFunction &cloneFunction const ShadowNodeCloneFunction &cloneFunction
): ):
ConcreteShadowNode<concreteComponentName, ViewPropsT, ViewEventEmitterT>( ConcreteShadowNode<concreteComponentName, ViewPropsT, ViewEventEmitterT>(
tag, fragment,
rootTag,
props,
eventEmitter,
children,
cloneFunction cloneFunction
), ),
AccessibleShadowNode( AccessibleShadowNode(
props std::static_pointer_cast<const ConcreteViewProps>(fragment.props)
), ),
YogaLayoutableShadowNode() { YogaLayoutableShadowNode() {
YogaLayoutableShadowNode::setProps(*props); YogaLayoutableShadowNode::setProps(*std::static_pointer_cast<const ConcreteViewProps>(fragment.props));
YogaLayoutableShadowNode::setChildren(ConcreteShadowNode<concreteComponentName, ViewPropsT, ViewEventEmitterT>::template getChildrenSlice<YogaLayoutableShadowNode>()); YogaLayoutableShadowNode::setChildren(ConcreteShadowNode<concreteComponentName, ViewPropsT, ViewEventEmitterT>::template getChildrenSlice<YogaLayoutableShadowNode>());
}; };
ConcreteViewShadowNode( ConcreteViewShadowNode(
const SharedConcreteViewShadowNode &shadowNode, const SharedShadowNode &sourceShadowNode,
const SharedConcreteViewProps &props, const ShadowNodeFragment &fragment
const SharedConcreteViewEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children
): ):
ConcreteShadowNode<concreteComponentName, ViewPropsT, ViewEventEmitterT>( ConcreteShadowNode<concreteComponentName, ViewPropsT, ViewEventEmitterT>(
shadowNode, sourceShadowNode,
props, fragment
eventEmitter,
children
), ),
AccessibleShadowNode( AccessibleShadowNode(
shadowNode, std::static_pointer_cast<const ConcreteViewShadowNode>(sourceShadowNode),
props std::static_pointer_cast<const ConcreteViewProps>(fragment.props)
), ),
YogaLayoutableShadowNode( YogaLayoutableShadowNode(
*shadowNode *std::static_pointer_cast<const ConcreteViewShadowNode>(sourceShadowNode)
) { ) {
if (props) { if (fragment.props) {
YogaLayoutableShadowNode::setProps(*props); YogaLayoutableShadowNode::setProps(*std::static_pointer_cast<const ConcreteViewProps>(fragment.props));
} }
if (children) { if (fragment.children) {
YogaLayoutableShadowNode::setChildren(ConcreteShadowNode<concreteComponentName, ViewPropsT, ViewEventEmitterT>::template getChildrenSlice<YogaLayoutableShadowNode>()); YogaLayoutableShadowNode::setChildren(ConcreteShadowNode<concreteComponentName, ViewPropsT, ViewEventEmitterT>::template getChildrenSlice<YogaLayoutableShadowNode>());
} }
}; };
@ -119,7 +106,7 @@ public:
LayoutableShadowNode *cloneAndReplaceChild(LayoutableShadowNode *child, int suggestedIndex = -1) override { LayoutableShadowNode *cloneAndReplaceChild(LayoutableShadowNode *child, int suggestedIndex = -1) override {
ensureUnsealed(); ensureUnsealed();
auto childShadowNode = static_cast<const ConcreteViewShadowNode *>(child); auto childShadowNode = static_cast<const ConcreteViewShadowNode *>(child);
auto clonedChildShadowNode = std::static_pointer_cast<ConcreteViewShadowNode>(childShadowNode->clone()); auto clonedChildShadowNode = std::static_pointer_cast<ConcreteViewShadowNode>(childShadowNode->clone({}));
ShadowNode::replaceChild(childShadowNode->shared_from_this(), clonedChildShadowNode, suggestedIndex); ShadowNode::replaceChild(childShadowNode->shared_from_this(), clonedChildShadowNode, suggestedIndex);
return clonedChildShadowNode.get(); return clonedChildShadowNode.get();
} }

View File

@ -17,7 +17,7 @@ namespace react {
class AccessibleShadowNode; class AccessibleShadowNode;
typedef std::shared_ptr<const AccessibleShadowNode> SharedAccessibleShadowNode; using SharedAccessibleShadowNode = std::shared_ptr<const AccessibleShadowNode>;
class AccessibleShadowNode { class AccessibleShadowNode {

View File

@ -54,11 +54,13 @@ public:
assert(std::dynamic_pointer_cast<const ConcreteEventEmitter>(eventEmitter)); assert(std::dynamic_pointer_cast<const ConcreteEventEmitter>(eventEmitter));
const auto &shadowNode = std::make_shared<ShadowNodeT>( const auto &shadowNode = std::make_shared<ShadowNodeT>(
tag, ShadowNodeFragment {
rootTag, .tag = tag,
std::static_pointer_cast<const ConcreteProps>(props), .rootTag = rootTag,
std::static_pointer_cast<const ConcreteEventEmitter>(eventEmitter), .props = props,
ShadowNode::emptySharedShadowNodeSharedList(), .eventEmitter = eventEmitter,
.children = ShadowNode::emptySharedShadowNodeSharedList()
},
getCloneFunction() getCloneFunction()
); );
@ -77,9 +79,11 @@ public:
const auto &shadowNode = std::make_shared<ShadowNodeT>( const auto &shadowNode = std::make_shared<ShadowNodeT>(
std::static_pointer_cast<const ShadowNodeT>(sourceShadowNode), std::static_pointer_cast<const ShadowNodeT>(sourceShadowNode),
std::static_pointer_cast<const ConcreteProps>(props), ShadowNodeFragment {
std::static_pointer_cast<const ConcreteEventEmitter>(eventEmitter), .props = props,
children .eventEmitter = eventEmitter,
.children = children
}
); );
adopt(shadowNode); adopt(shadowNode);
@ -124,9 +128,9 @@ private:
ShadowNodeCloneFunction getCloneFunction() const { ShadowNodeCloneFunction getCloneFunction() const {
if (!cloneFunction_) { if (!cloneFunction_) {
cloneFunction_ = [this](const SharedShadowNode &shadowNode, const SharedProps &props, const SharedEventEmitter &eventEmitter, const SharedShadowNodeSharedList &children) { cloneFunction_ = [this](const SharedShadowNode &shadowNode, const ShadowNodeFragment &fragment) {
assert(std::dynamic_pointer_cast<const ShadowNodeT>(shadowNode)); assert(std::dynamic_pointer_cast<const ShadowNodeT>(shadowNode));
return this->cloneShadowNode(shadowNode, props, eventEmitter, children); return this->cloneShadowNode(shadowNode, fragment.props, fragment.eventEmitter, fragment.children);
}; };
} }

View File

@ -23,42 +23,33 @@ SharedShadowNodeSharedList ShadowNode::emptySharedShadowNodeSharedList() {
#pragma mark - Constructors #pragma mark - Constructors
ShadowNode::ShadowNode( ShadowNode::ShadowNode(
const Tag &tag, const ShadowNodeFragment &fragment,
const Tag &rootTag,
const SharedProps &props,
const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children,
const ShadowNodeCloneFunction &cloneFunction const ShadowNodeCloneFunction &cloneFunction
): ):
tag_(tag), tag_(fragment.tag),
rootTag_(rootTag), rootTag_(fragment.rootTag),
props_(props), props_(fragment.props),
eventEmitter_(eventEmitter), eventEmitter_(fragment.eventEmitter),
children_(std::make_shared<SharedShadowNodeList>(*children)), children_(std::make_shared<SharedShadowNodeList>(*fragment.children)),
cloneFunction_(cloneFunction), cloneFunction_(cloneFunction),
revision_(1) {} revision_(1) {}
ShadowNode::ShadowNode( ShadowNode::ShadowNode(
const SharedShadowNode &shadowNode, const SharedShadowNode &sourceShadowNode,
const SharedProps &props, const ShadowNodeFragment &fragment
const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children
): ):
tag_(shadowNode->tag_), tag_(fragment.tag ?: sourceShadowNode->tag_),
rootTag_(shadowNode->rootTag_), rootTag_(fragment.rootTag ?: sourceShadowNode->rootTag_),
props_(props ? props : shadowNode->props_), props_(fragment.props ?: sourceShadowNode->props_),
eventEmitter_(eventEmitter ? eventEmitter : shadowNode->eventEmitter_), eventEmitter_(fragment.eventEmitter ?: sourceShadowNode->eventEmitter_),
children_(std::make_shared<SharedShadowNodeList>(*(children ? children : shadowNode->children_))), children_(std::make_shared<SharedShadowNodeList>(*(fragment.children ?: sourceShadowNode->children_))),
localData_(shadowNode->localData_), localData_(fragment.localData ?: sourceShadowNode->localData_),
cloneFunction_(shadowNode->cloneFunction_), cloneFunction_(sourceShadowNode->cloneFunction_),
revision_(shadowNode->revision_ + 1) {} revision_(sourceShadowNode->revision_ + 1) {}
UnsharedShadowNode ShadowNode::clone( UnsharedShadowNode ShadowNode::clone(const ShadowNodeFragment &fragment) const {
const SharedProps &props,
const SharedShadowNodeSharedList &children
) const {
assert(cloneFunction_); assert(cloneFunction_);
return cloneFunction_(shared_from_this(), props_, eventEmitter_, children_); return cloneFunction_(shared_from_this(), fragment);
} }
#pragma mark - Getters #pragma mark - Getters

View File

@ -29,45 +29,51 @@ using SharedShadowNodeList = std::vector<std::shared_ptr<const ShadowNode>>;
using SharedShadowNodeSharedList = std::shared_ptr<const SharedShadowNodeList>; using SharedShadowNodeSharedList = std::shared_ptr<const SharedShadowNodeList>;
using SharedShadowNodeUnsharedList = std::shared_ptr<SharedShadowNodeList>; using SharedShadowNodeUnsharedList = std::shared_ptr<SharedShadowNodeList>;
struct ShadowNodeFragment {
Tag tag;
Tag rootTag;
SharedProps props;
SharedEventEmitter eventEmitter;
SharedShadowNodeSharedList children;
SharedLocalData localData;
};
using ShadowNodeCloneFunction = std::function<UnsharedShadowNode( using ShadowNodeCloneFunction = std::function<UnsharedShadowNode(
const SharedShadowNode &shadowNode, const SharedShadowNode &sourceShadowNode,
const SharedProps &props, const ShadowNodeFragment &fragment
const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children
)>; )>;
class ShadowNode: class ShadowNode:
public virtual Sealable, public virtual Sealable,
public virtual DebugStringConvertible, public virtual DebugStringConvertible,
public std::enable_shared_from_this<ShadowNode> { public std::enable_shared_from_this<ShadowNode> {
public: public:
static SharedShadowNodeSharedList emptySharedShadowNodeSharedList(); static SharedShadowNodeSharedList emptySharedShadowNodeSharedList();
#pragma mark - Constructors #pragma mark - Constructors
/*
* Creates a Shadow Node based on fields specified in a `fragment`.
*/
ShadowNode( ShadowNode(
const Tag &tag, const ShadowNodeFragment &fragment,
const Tag &rootTag,
const SharedProps &props,
const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children,
const ShadowNodeCloneFunction &cloneFunction const ShadowNodeCloneFunction &cloneFunction
); );
/*
* Creates a Shadow Node via cloning given `sourceShadowNode` and
* applying fields from given `fragment`.
*/
ShadowNode( ShadowNode(
const SharedShadowNode &shadowNode, const SharedShadowNode &sourceShadowNode,
const SharedProps &props, const ShadowNodeFragment &fragment
const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children
); );
/* /*
* Clones the shadow node using stored `cloneFunction`. * Clones the shadow node using stored `cloneFunction`.
*/ */
UnsharedShadowNode clone( UnsharedShadowNode clone(const ShadowNodeFragment &fragment) const;
const SharedProps &props = nullptr,
const SharedShadowNodeSharedList &children = nullptr
) const;
#pragma mark - Getters #pragma mark - Getters

View File

@ -28,7 +28,15 @@ TEST(ShadowNodeTest, handleProps) {
} }
TEST(ShadowNodeTest, handleShadowNodeCreation) { TEST(ShadowNodeTest, handleShadowNodeCreation) {
auto node = std::make_shared<TestShadowNode>(9, 1, std::make_shared<const TestProps>(), nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr); auto node = std::make_shared<TestShadowNode>(
ShadowNodeFragment {
.tag = 9,
.rootTag = 1,
.props = std::make_shared<const TestProps>(),
.children = ShadowNode::emptySharedShadowNodeSharedList()
},
nullptr
);
ASSERT_FALSE(node->getSealed()); ASSERT_FALSE(node->getSealed());
ASSERT_STREQ(node->getComponentName().c_str(), "Test"); ASSERT_STREQ(node->getComponentName().c_str(), "Test");
@ -45,8 +53,16 @@ TEST(ShadowNodeTest, handleShadowNodeCreation) {
} }
TEST(ShadowNodeTest, handleShadowNodeSimpleCloning) { TEST(ShadowNodeTest, handleShadowNodeSimpleCloning) {
auto node = std::make_shared<TestShadowNode>(9, 1, std::make_shared<const TestProps>(), nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr); auto node = std::make_shared<TestShadowNode>(
auto node2 = std::make_shared<TestShadowNode>(node, nullptr, nullptr, nullptr); ShadowNodeFragment {
.tag = 9,
.rootTag = 1,
.props = std::make_shared<const TestProps>(),
.children = ShadowNode::emptySharedShadowNodeSharedList()
},
nullptr
);
auto node2 = std::make_shared<TestShadowNode>(node, ShadowNodeFragment {});
ASSERT_STREQ(node->getComponentName().c_str(), "Test"); ASSERT_STREQ(node->getComponentName().c_str(), "Test");
ASSERT_EQ(node->getTag(), 9); ASSERT_EQ(node->getTag(), 9);
@ -56,9 +72,9 @@ TEST(ShadowNodeTest, handleShadowNodeSimpleCloning) {
TEST(ShadowNodeTest, handleShadowNodeMutation) { TEST(ShadowNodeTest, handleShadowNodeMutation) {
auto props = std::make_shared<const TestProps>(); auto props = std::make_shared<const TestProps>();
auto node1 = std::make_shared<TestShadowNode>(1, 1, props, nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr); auto node1 = std::make_shared<TestShadowNode>(ShadowNodeFragment {.tag = 1, .rootTag = 1, .props = std::make_shared<const TestProps>(), .children = ShadowNode::emptySharedShadowNodeSharedList()}, nullptr);
auto node2 = std::make_shared<TestShadowNode>(2, 1, props, nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr); auto node2 = std::make_shared<TestShadowNode>(ShadowNodeFragment {.tag = 2, .rootTag = 1, .props = std::make_shared<const TestProps>(), .children = ShadowNode::emptySharedShadowNodeSharedList()}, nullptr);
auto node3 = std::make_shared<TestShadowNode>(3, 1, props, nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr); auto node3 = std::make_shared<TestShadowNode>(ShadowNodeFragment {.tag = 3, .rootTag = 1, .props = std::make_shared<const TestProps>(), .children = ShadowNode::emptySharedShadowNodeSharedList()}, nullptr);
node1->appendChild(node2); node1->appendChild(node2);
node1->appendChild(node3); node1->appendChild(node3);
@ -67,7 +83,7 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) {
ASSERT_EQ(node1Children->at(0), node2); ASSERT_EQ(node1Children->at(0), node2);
ASSERT_EQ(node1Children->at(1), node3); ASSERT_EQ(node1Children->at(1), node3);
auto node4 = std::make_shared<TestShadowNode>(node2, nullptr, nullptr, nullptr); auto node4 = std::make_shared<TestShadowNode>(node2, ShadowNodeFragment {});
node1->replaceChild(node2, node4); node1->replaceChild(node2, node4);
node1Children = node1->getChildren(); node1Children = node1->getChildren();
ASSERT_EQ(node1Children->size(), 2); ASSERT_EQ(node1Children->size(), 2);
@ -83,34 +99,33 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) {
// No more mutation after sealing. // No more mutation after sealing.
EXPECT_THROW(node4->setLocalData(nullptr), std::runtime_error); EXPECT_THROW(node4->setLocalData(nullptr), std::runtime_error);
auto node5 = std::make_shared<TestShadowNode>(node4, nullptr, nullptr, nullptr); auto node5 = std::make_shared<TestShadowNode>(node4, ShadowNodeFragment {});
node5->setLocalData(nullptr); node5->setLocalData(nullptr);
ASSERT_EQ(node5->getLocalData(), nullptr); ASSERT_EQ(node5->getLocalData(), nullptr);
} }
TEST(ShadowNodeTest, handleCloneFunction) { TEST(ShadowNodeTest, handleCloneFunction) {
auto firstNode = std::make_shared<TestShadowNode>(9, 1, std::make_shared<const TestProps>(), nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr); auto firstNode = std::make_shared<TestShadowNode>(ShadowNodeFragment {.tag = 9, .rootTag = 1, .props = std::make_shared<const TestProps>(), .children = ShadowNode::emptySharedShadowNodeSharedList()}, nullptr);
// The shadow node is not clonable if `cloneFunction` is not provided, // The shadow node is not clonable if `cloneFunction` is not provided,
ASSERT_DEATH_IF_SUPPORTED(firstNode->clone(), "cloneFunction_"); ASSERT_DEATH_IF_SUPPORTED(firstNode->clone({}), "cloneFunction_");
auto secondNode = std::make_shared<TestShadowNode>( auto secondNode = std::make_shared<TestShadowNode>(
9, ShadowNodeFragment {
1, .tag = 9,
std::make_shared<const TestProps>(), .rootTag = 1,
nullptr, .props = std::make_shared<const TestProps>(),
ShadowNode::emptySharedShadowNodeSharedList(), .children = ShadowNode::emptySharedShadowNodeSharedList()
[](const SharedShadowNode &shadowNode, const SharedProps &props, const SharedEventEmitter &eventEmitter, const SharedShadowNodeSharedList &children) { },
[](const SharedShadowNode &shadowNode, const ShadowNodeFragment &fragment) {
return std::make_shared<TestShadowNode>( return std::make_shared<TestShadowNode>(
std::static_pointer_cast<const TestShadowNode>(shadowNode), std::static_pointer_cast<const TestShadowNode>(shadowNode),
props, fragment
nullptr,
children
); );
} }
); );
auto secondNodeClone = secondNode->clone(); auto secondNodeClone = secondNode->clone({});
// Those two nodes are *not* same. // Those two nodes are *not* same.
ASSERT_NE(secondNode, secondNodeClone); ASSERT_NE(secondNode, secondNodeClone);
@ -134,9 +149,9 @@ TEST(ShadowNodeTest, handleLocalData) {
auto localDataOver9000 = std::make_shared<TestLocalData>(); auto localDataOver9000 = std::make_shared<TestLocalData>();
localDataOver9000->setNumber(9001); localDataOver9000->setNumber(9001);
auto props = std::make_shared<const TestProps>(); auto props = std::make_shared<const TestProps>();
auto firstNode = std::make_shared<TestShadowNode>(9, 1, props, nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr); auto firstNode = std::make_shared<TestShadowNode>(ShadowNodeFragment {.tag = 9, .rootTag = 1, .props = props, .children = ShadowNode::emptySharedShadowNodeSharedList()}, nullptr);
auto secondNode = std::make_shared<TestShadowNode>(9, 1, props, nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr); auto secondNode = std::make_shared<TestShadowNode>(ShadowNodeFragment {.tag = 9, .rootTag = 1, .props = props, .children = ShadowNode::emptySharedShadowNodeSharedList()}, nullptr);
auto thirdNode = std::make_shared<TestShadowNode>(9, 1, props, nullptr, ShadowNode::emptySharedShadowNodeSharedList(), nullptr); auto thirdNode = std::make_shared<TestShadowNode>(ShadowNodeFragment {.tag = 9, .rootTag = 1, .props = props, .children = ShadowNode::emptySharedShadowNodeSharedList()}, nullptr);
firstNode->setLocalData(localData42); firstNode->setLocalData(localData42);
secondNode->setLocalData(localData42); secondNode->setLocalData(localData42);

View File

@ -18,13 +18,15 @@ namespace react {
ShadowTree::ShadowTree(Tag rootTag): ShadowTree::ShadowTree(Tag rootTag):
rootTag_(rootTag) { rootTag_(rootTag) {
const auto &noopEventEmitter = std::make_shared<const ViewEventEmitter>(nullptr, rootTag, nullptr); const auto noopEventEmitter = std::make_shared<const ViewEventEmitter>(nullptr, rootTag, nullptr);
rootShadowNode_ = std::make_shared<RootShadowNode>( rootShadowNode_ = std::make_shared<RootShadowNode>(
rootTag, ShadowNodeFragment {
rootTag, .tag = rootTag,
RootShadowNode::defaultSharedProps(), .rootTag = rootTag,
noopEventEmitter, .props = RootShadowNode::defaultSharedProps(),
ShadowNode::emptySharedShadowNodeSharedList(), .eventEmitter = noopEventEmitter,
.children = ShadowNode::emptySharedShadowNodeSharedList(),
},
nullptr nullptr
); );
} }
@ -51,14 +53,20 @@ void ShadowTree::constraintLayout(const LayoutConstraints &layoutConstraints, co
UnsharedRootShadowNode ShadowTree::cloneRootShadowNode(const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext) const { UnsharedRootShadowNode ShadowTree::cloneRootShadowNode(const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext) const {
auto oldRootShadowNode = rootShadowNode_; auto oldRootShadowNode = rootShadowNode_;
const auto &props = std::make_shared<const RootProps>(*oldRootShadowNode->getProps(), layoutConstraints, layoutContext); const auto &props = std::make_shared<const RootProps>(*oldRootShadowNode->getProps(), layoutConstraints, layoutContext);
auto newRootShadowNode = std::make_shared<RootShadowNode>(oldRootShadowNode, props, nullptr, nullptr); auto newRootShadowNode =
std::make_shared<RootShadowNode>(oldRootShadowNode, ShadowNodeFragment {.props = props});
return newRootShadowNode; return newRootShadowNode;
} }
void ShadowTree::complete(const SharedShadowNodeUnsharedList &rootChildNodes) { void ShadowTree::complete(const SharedShadowNodeUnsharedList &rootChildNodes) {
auto oldRootShadowNode = rootShadowNode_; auto oldRootShadowNode = rootShadowNode_;
auto newRootShadowNode = auto newRootShadowNode =
std::make_shared<RootShadowNode>(oldRootShadowNode, nullptr, nullptr, SharedShadowNodeSharedList(rootChildNodes)); std::make_shared<RootShadowNode>(
oldRootShadowNode,
ShadowNodeFragment {
.children = SharedShadowNodeSharedList(rootChildNodes)
}
);
complete(newRootShadowNode); complete(newRootShadowNode);
} }