From 5bf6726baee81ad9d72f856642092c08f058f5fe Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 26 Feb 2020 22:03:14 -0800 Subject: [PATCH] Fabric: Stop using `getChildrenSlice` in ConcreteViewShadowNode Summary: D19963353 mentioned the infrastructure that re-routes methods calls related to adding and cloning children between YogaLayoutableShadowNode and ShadowNode. `cloneAndReplaceChild` is exactly this. It was implemented as a virtual method that is called from `ConcreteViewShadowNode`. The whole process requires building a list of children of some class and passing that as a list of pointers. Now we don't need it all that because we can call directly and statically. That change will allow us to simplify that infra even more in the future diffs. With all previous changes, now we can implement `getYogaLayoutableChildren` inside `YogaLayoutableShadowNode` and call that statically. Eventually, that will allow us to remove templated `getChildrenSlice`. Previously the call for that method must be in `ConcreteViewShadowNode`, now it's not true anymore which we will use later to even better goodness. Changelog: [Internal] Fabric-specific internal change. Reviewed By: mdvacca Differential Revision: D20052020 fbshipit-source-id: e5c819a4d21b2dbcd08f3439e1783e3a9cba5ef4 --- .../components/view/ConcreteViewShadowNode.h | 5 ++--- .../view/yoga/YogaLayoutableShadowNode.cpp | 14 ++++++++++++++ .../view/yoga/YogaLayoutableShadowNode.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h b/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h index f9618b7713..06d1d1818e 100644 --- a/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h +++ b/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h @@ -62,7 +62,7 @@ class ConcreteViewShadowNode : public ConcreteShadowNode< YogaLayoutableShadowNode::setProps( *std::static_pointer_cast(fragment.props)); YogaLayoutableShadowNode::setChildren( - BaseShadowNode::template getChildrenSlice()); + YogaLayoutableShadowNode::getYogaLayoutableChildren()); } ConcreteViewShadowNode( @@ -76,8 +76,7 @@ class ConcreteViewShadowNode : public ConcreteShadowNode< if (fragment.children) { YogaLayoutableShadowNode::setChildren( - BaseShadowNode::template getChildrenSlice< - YogaLayoutableShadowNode>()); + YogaLayoutableShadowNode::getYogaLayoutableChildren()); } } diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp index 75e512a1bc..aa4a3832bb 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp @@ -123,6 +123,20 @@ void YogaLayoutableShadowNode::appendChildYogaNode( childYogaNodeRawPtr, yogaNodeRawPtr->getChildren().size()); } +YogaLayoutableShadowNode::UnsharedList +YogaLayoutableShadowNode::getYogaLayoutableChildren() const { + YogaLayoutableShadowNode::UnsharedList layoutableChildren; + for (auto const &childShadowNode : getChildren()) { + auto layoutableChildShadowNode = + traitCast(childShadowNode.get()); + if (layoutableChildShadowNode) { + layoutableChildren.push_back( + const_cast(layoutableChildShadowNode)); + } + } + return layoutableChildren; +} + void YogaLayoutableShadowNode::setChildren( YogaLayoutableShadowNode::UnsharedList children) { if (getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) { diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h index f75c56c485..f199455b80 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h @@ -90,6 +90,8 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode { void layoutChildren(LayoutContext layoutContext) override; + YogaLayoutableShadowNode::UnsharedList getYogaLayoutableChildren() const; + LayoutableShadowNode::UnsharedList getLayoutableChildNodes() const override; protected: