mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 11:57:46 +08:00
Fabric: Simplified ViewShadowNode::cloneAndReplaceChild
Summary: Using methods of the base class instead of custom implementation. Reviewed By: fkgozali Differential Revision: D7467795 fbshipit-source-id: 4d168b72880f6900bf8b747e1d655c10140e0c79
This commit is contained in:
committed by
Facebook Github Bot
parent
a38f32a5a6
commit
fec0a51e85
@@ -92,26 +92,14 @@ SharedLayoutableShadowNodeList ViewShadowNode::getChildren() const {
|
||||
SharedLayoutableShadowNode ViewShadowNode::cloneAndReplaceChild(const SharedLayoutableShadowNode &child) {
|
||||
ensureUnsealed();
|
||||
|
||||
// We cannot mutate `children_` in place here because it is a *shared*
|
||||
// data structure which means other `ShadowNodes` might refer to its old value.
|
||||
// So, we have to clone this and only then mutate.
|
||||
auto nonConstChildrenCopy = SharedShadowNodeList(*children_);
|
||||
|
||||
auto viewShadowNodeChild = std::dynamic_pointer_cast<const ViewShadowNode>(child);
|
||||
assert(viewShadowNodeChild);
|
||||
|
||||
auto viewShadowNodeChildClone = std::make_shared<const ViewShadowNode>(viewShadowNodeChild);
|
||||
|
||||
std::replace(
|
||||
nonConstChildrenCopy.begin(),
|
||||
nonConstChildrenCopy.end(),
|
||||
std::static_pointer_cast<const ShadowNode>(viewShadowNodeChild),
|
||||
std::static_pointer_cast<const ShadowNode>(viewShadowNodeChildClone)
|
||||
);
|
||||
|
||||
children_ = std::make_shared<const SharedShadowNodeList>(nonConstChildrenCopy);
|
||||
|
||||
ShadowNode::replaceChild(viewShadowNodeChild, viewShadowNodeChildClone);
|
||||
return std::static_pointer_cast<const LayoutableShadowNode>(viewShadowNodeChildClone);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
Reference in New Issue
Block a user