Skip to content

Commit cdbc211

Browse files
sherginfacebook-github-bot
authored andcommitted
Fabric: Refinement of BaseTraits chain
Summary: Here we refine the `ShadowNode::BaseTraits` static method. Before this change, ConcreteViewShadowNode<> enforces Layoutable and YogaLayoutable traits. This change moves that responsibility to LayoutableShadowNode and YogaLayoutableShadowNode which makes overall logic more coherent. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D20052027 fbshipit-source-id: fd25264204b0232b1dbbff6f9dfefd9fbcb146c4
1 parent 0c50ba5 commit cdbc211

File tree

7 files changed

+25
-3
lines changed

7 files changed

+25
-3
lines changed

ReactCommon/fabric/components/view/ConcreteViewShadowNode.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ class ConcreteViewShadowNode : public ConcreteShadowNode<
5858

5959
static ShadowNodeTraits BaseTraits() {
6060
auto traits = BaseShadowNode::BaseTraits();
61-
traits.set(ShadowNodeTraits::Trait::LayoutableKind);
62-
traits.set(ShadowNodeTraits::Trait::YogaLayoutableKind);
6361
traits.set(ShadowNodeTraits::Trait::ViewKind);
6462
return traits;
6563
}

ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
namespace facebook {
2222
namespace react {
2323

24+
ShadowNodeTraits YogaLayoutableShadowNode::BaseTraits() {
25+
auto traits = LayoutableShadowNode::BaseTraits();
26+
traits.set(ShadowNodeTraits::Trait::YogaLayoutableKind);
27+
return traits;
28+
}
29+
2430
YogaLayoutableShadowNode::YogaLayoutableShadowNode(
2531
ShadowNodeFragment const &fragment,
2632
ShadowNodeFamily::Shared const &family,

ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode {
2828
YogaLayoutableShadowNode *,
2929
kShadowNodeChildrenSmallVectorSize>;
3030

31+
static ShadowNodeTraits BaseTraits();
32+
3133
#pragma mark - Constructors
3234

3335
YogaLayoutableShadowNode(

ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ LayoutableShadowNode::LayoutableShadowNode(
8181
layoutMetrics_(static_cast<LayoutableShadowNode const &>(sourceShadowNode)
8282
.layoutMetrics_) {}
8383

84+
ShadowNodeTraits LayoutableShadowNode::BaseTraits() {
85+
auto traits = ShadowNodeTraits{};
86+
traits.set(ShadowNodeTraits::Trait::LayoutableKind);
87+
return traits;
88+
}
89+
8490
LayoutMetrics LayoutableShadowNode::getLayoutMetrics() const {
8591
return layoutMetrics_;
8692
}

ReactCommon/fabric/core/layout/LayoutableShadowNode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class LayoutableShadowNode : public ShadowNode {
4141
ShadowNode const &sourceShadowNode,
4242
ShadowNodeFragment const &fragment);
4343

44+
static ShadowNodeTraits BaseTraits();
45+
4446
class LayoutInspectingPolicy final {
4547
public:
4648
bool includeTransform{true};

ReactCommon/fabric/core/shadownode/ConcreteShadowNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class ConcreteShadowNode : public BaseShadowNodeT {
6363
* Reimplement in subclasses to declare class-specific traits.
6464
*/
6565
static ShadowNodeTraits BaseTraits() {
66-
return ShadowNodeTraits{};
66+
return BaseShadowNodeT::BaseTraits();
6767
}
6868

6969
static SharedConcreteProps Props(

ReactCommon/fabric/core/shadownode/ShadowNode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ class ShadowNode : public Sealable, public DebugStringConvertible {
6363
*/
6464
static bool sameFamily(const ShadowNode &first, const ShadowNode &second);
6565

66+
/*
67+
* A set of traits associated with a particular class.
68+
* Reimplement in subclasses to declare class-specific traits.
69+
*/
70+
static ShadowNodeTraits BaseTraits() {
71+
return ShadowNodeTraits{};
72+
}
73+
6674
#pragma mark - Constructors
6775

6876
/*

0 commit comments

Comments
 (0)