mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
Summary: This pull request removes the designated initializers in `RootShadowNode.cpp`. This will help improve the portability of this file. [General] [Fixed] - Removed designated initializers in `RootShadowNode` Pull Request resolved: https://github.com/facebook/react-native/pull/23715 Differential Revision: D14305167 Pulled By: shergin fbshipit-source-id: e394580f103fdb59cf078828b5d2ee6df6cc534d
82 lines
2.5 KiB
C++
82 lines
2.5 KiB
C++
/**
|
|
* Copyright (c) Facebook, Inc. and its 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 <react/components/view/conversions.h>
|
|
#include <react/debug/SystraceSection.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
const char RootComponentName[] = "RootView";
|
|
|
|
void RootShadowNode::layout() {
|
|
SystraceSection s("RootShadowNode::layout");
|
|
ensureUnsealed();
|
|
layout(getProps()->layoutContext);
|
|
|
|
// This is the rare place where shadow node must layout (set `layoutMetrics`)
|
|
// itself because there is no a parent node which usually should do it.
|
|
setLayoutMetrics(layoutMetricsFromYogaNode(yogaNode_));
|
|
}
|
|
|
|
UnsharedRootShadowNode RootShadowNode::clone(
|
|
const LayoutConstraints &layoutConstraints,
|
|
const LayoutContext &layoutContext) const {
|
|
auto props = std::make_shared<const RootProps>(
|
|
*getProps(), layoutConstraints, layoutContext);
|
|
auto newRootShadowNode = std::make_shared<RootShadowNode>(
|
|
*this,
|
|
ShadowNodeFragment{
|
|
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
|
|
/* .rootTag = */ ShadowNodeFragment::surfaceIdPlaceholder(),
|
|
/* .props = */ props,
|
|
});
|
|
return newRootShadowNode;
|
|
}
|
|
|
|
UnsharedRootShadowNode RootShadowNode::clone(
|
|
const SharedShadowNode &oldShadowNode,
|
|
const SharedShadowNode &newShadowNode) const {
|
|
std::vector<std::reference_wrapper<const ShadowNode>> ancestors;
|
|
|
|
if (!oldShadowNode->constructAncestorPath(*this, ancestors)) {
|
|
return UnsharedRootShadowNode{nullptr};
|
|
}
|
|
|
|
auto oldChild = oldShadowNode;
|
|
auto newChild = newShadowNode;
|
|
|
|
for (const auto &ancestor : ancestors) {
|
|
auto oldParent = ancestor.get().shared_from_this();
|
|
|
|
auto children = oldParent->getChildren();
|
|
std::replace(children.begin(), children.end(), oldChild, newChild);
|
|
|
|
auto sharedChildren = std::make_shared<SharedShadowNodeList>(children);
|
|
auto newParent = oldParent->clone({
|
|
/* .tag = */ ShadowNodeFragment::tagPlaceholder(),
|
|
/* .rootTag = */ ShadowNodeFragment::surfaceIdPlaceholder(),
|
|
/* .props = */ ShadowNodeFragment::propsPlaceholder(),
|
|
/* .eventEmitter = */ ShadowNodeFragment::eventEmitterPlaceholder(),
|
|
/* .children = */ sharedChildren,
|
|
});
|
|
|
|
newParent->replaceChild(oldChild, newChild);
|
|
|
|
oldChild = oldParent;
|
|
newChild = newParent;
|
|
}
|
|
|
|
return std::const_pointer_cast<RootShadowNode>(
|
|
std::static_pointer_cast<const RootShadowNode>(newChild));
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|