From 0c50ba537666e3e8d76a00a010edced8d88d77dc Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 26 Feb 2020 22:03:14 -0800 Subject: [PATCH] Fabric: Moving logic from `ConcreteViewShadowNode` constructors to `YogaLayoutableShadowNode` constructors Summary: Now we can move custom to `YogaLayoutableShadowNode` code from `ConcreteViewShadowNode<>` template to `YogaLayoutableShadowNode` itself reducing the amount of templated code and reduce overall complexity. Note, here we have to do `dynamic_cast` for now, we will address that in coming diffs. Changelog: [Internal] Fabric-specific internal change. Reviewed By: mdvacca Differential Revision: D20052021 fbshipit-source-id: dac5969a97b75e54c7728a1ca8161922bd2245ca --- .../components/view/ConcreteViewShadowNode.h | 26 +------------------ .../view/yoga/YogaLayoutableShadowNode.cpp | 13 +++++++++- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h b/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h index 06d1d1818e4..6c5e15a7786 100644 --- a/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h +++ b/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h @@ -54,31 +54,7 @@ class ConcreteViewShadowNode : public ConcreteShadowNode< Ts...>; using ConcreteViewProps = ViewPropsT; - ConcreteViewShadowNode( - ShadowNodeFragment const &fragment, - ShadowNodeFamily::Shared const &family, - ShadowNodeTraits traits) - : BaseShadowNode(fragment, family, traits) { - YogaLayoutableShadowNode::setProps( - *std::static_pointer_cast(fragment.props)); - YogaLayoutableShadowNode::setChildren( - YogaLayoutableShadowNode::getYogaLayoutableChildren()); - } - - ConcreteViewShadowNode( - ShadowNode const &sourceShadowNode, - ShadowNodeFragment const &fragment) - : BaseShadowNode(sourceShadowNode, fragment) { - if (fragment.props) { - YogaLayoutableShadowNode::setProps( - *std::static_pointer_cast(fragment.props)); - } - - if (fragment.children) { - YogaLayoutableShadowNode::setChildren( - YogaLayoutableShadowNode::getYogaLayoutableChildren()); - } - } + using BaseShadowNode::BaseShadowNode; static ShadowNodeTraits BaseTraits() { auto traits = BaseShadowNode::BaseTraits(); diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp index fc78ce154e7..2f200b4952c 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp @@ -29,6 +29,9 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode( yogaConfig_(nullptr), yogaNode_(&initializeYogaConfig(yogaConfig_)) { yogaNode_.setContext(this); + + setProps(dynamic_cast(*fragment.props)); + setChildren(YogaLayoutableShadowNode::getYogaLayoutableChildren()); } YogaLayoutableShadowNode::YogaLayoutableShadowNode( @@ -47,6 +50,14 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode( assert( static_cast(sourceShadowNode) .yogaNode_.isDirty() == yogaNode_.isDirty()); + + if (fragment.props) { + setProps(dynamic_cast(*fragment.props)); + } + + if (fragment.children) { + setChildren(YogaLayoutableShadowNode::getYogaLayoutableChildren()); + } } void YogaLayoutableShadowNode::cleanLayout() { @@ -165,7 +176,7 @@ void YogaLayoutableShadowNode::setChildren( yogaNode_.setDirty(!isClean); } -void YogaLayoutableShadowNode::setProps(const YogaStylableProps &props) { +void YogaLayoutableShadowNode::setProps(YogaStylableProps const &props) { ensureUnsealed(); // Resetting `dirty` flag only if `yogaStyle` portion of `Props` was changed.