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
This commit is contained in:
Valentin Shergin
2020-02-26 22:08:18 -08:00
committed by Facebook Github Bot
parent 7953c3e854
commit 5bf6726bae
3 changed files with 18 additions and 3 deletions
@@ -62,7 +62,7 @@ class ConcreteViewShadowNode : public ConcreteShadowNode<
YogaLayoutableShadowNode::setProps(
*std::static_pointer_cast<const ConcreteViewProps>(fragment.props));
YogaLayoutableShadowNode::setChildren(
BaseShadowNode::template getChildrenSlice<YogaLayoutableShadowNode>());
YogaLayoutableShadowNode::getYogaLayoutableChildren());
}
ConcreteViewShadowNode(
@@ -76,8 +76,7 @@ class ConcreteViewShadowNode : public ConcreteShadowNode<
if (fragment.children) {
YogaLayoutableShadowNode::setChildren(
BaseShadowNode::template getChildrenSlice<
YogaLayoutableShadowNode>());
YogaLayoutableShadowNode::getYogaLayoutableChildren());
}
}
@@ -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<YogaLayoutableShadowNode const *>(childShadowNode.get());
if (layoutableChildShadowNode) {
layoutableChildren.push_back(
const_cast<YogaLayoutableShadowNode *>(layoutableChildShadowNode));
}
}
return layoutableChildren;
}
void YogaLayoutableShadowNode::setChildren(
YogaLayoutableShadowNode::UnsharedList children) {
if (getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
@@ -90,6 +90,8 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode {
void layoutChildren(LayoutContext layoutContext) override;
YogaLayoutableShadowNode::UnsharedList getYogaLayoutableChildren() const;
LayoutableShadowNode::UnsharedList getLayoutableChildNodes() const override;
protected: