Skip to content

Commit

Permalink
Fabric: Simplifying usage of ConcreteComponentDescriptor
Browse files Browse the repository at this point in the history
Summary:
Now ConcreteComponentDescriptor can infer `ComponentName` from `ShadowNodeT` automatically,
so in the most cases we even don't need to create a subclass of that.

Reviewed By: fkgozali

Differential Revision: D8016965

fbshipit-source-id: d910597093c9f4c9f32ca06cb3ef1b12538b9543
  • Loading branch information
shergin authored and facebook-github-bot committed May 18, 2018
1 parent 8f50728 commit cc09d21
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ class ConcreteComponentDescriptor: public ComponentDescriptor {
return typeid(ShadowNodeT).hash_code();
}

ComponentName getComponentName() const override {
// Even if this looks suboptimal, it is the only way to call
// a virtual non-static method of `ShadowNodeT`.
// Because it is not a hot path (it is executed once per an app run),
// it's fine.
return std::make_shared<ShadowNodeT>(
0,
0,
nullptr,
std::make_shared<const ConcreteProps>(),
ShadowNode::emptySharedShadowNodeSharedList(),
nullptr
)->ShadowNodeT::getComponentName();
}

SharedShadowNode createShadowNode(
const Tag &tag,
const Tag &rootTag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
namespace facebook {
namespace react {

class ScrollViewComponentDescriptor final: public ConcreteComponentDescriptor<ScrollViewShadowNode> {
public:
ComponentName getComponentName() const override {
return "ScrollView";
}
};
using ScrollViewComponentDescriptor = ConcreteComponentDescriptor<ScrollViewShadowNode>;

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class ParagraphComponentDescriptor: public ConcreteComponentDescriptor<Paragraph
textLayoutManager_ = std::make_shared<TextLayoutManager>();
}

ComponentName getComponentName() const override {
return "Paragraph";
}

void adopt(UnsharedShadowNode shadowNode) const override {
ConcreteComponentDescriptor<ParagraphShadowNode>::adopt(shadowNode);

Expand Down
10 changes: 1 addition & 9 deletions ReactCommon/fabric/text/rawtext/RawTextComponentDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@
namespace facebook {
namespace react {

/*
* Descriptor for <RawText> component.
*/
class RawTextComponentDescriptor: public ConcreteComponentDescriptor<RawTextShadowNode> {
public:
ComponentName getComponentName() const override {
return "RawText";
}
};
using RawTextComponentDescriptor = ConcreteComponentDescriptor<RawTextShadowNode>;

} // namespace react
} // namespace facebook
8 changes: 1 addition & 7 deletions ReactCommon/fabric/text/text/TextComponentDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@
#pragma once

#include <fabric/core/ConcreteComponentDescriptor.h>
#include <fabric/text/TextProps.h>
#include <fabric/text/TextShadowNode.h>

namespace facebook {
namespace react {

class TextComponentDescriptor: public ConcreteComponentDescriptor<TextShadowNode> {
public:
ComponentName getComponentName() const override {
return "Text";
}
};
using TextComponentDescriptor = ConcreteComponentDescriptor<TextShadowNode>;

} // namespace react
} // namespace facebook
7 changes: 1 addition & 6 deletions ReactCommon/fabric/view/ViewComponentDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
namespace facebook {
namespace react {

class ViewComponentDescriptor: public ConcreteComponentDescriptor<ViewShadowNode> {
public:
ComponentName getComponentName() const override {
return "View";
}
};
using ViewComponentDescriptor = ConcreteComponentDescriptor<ViewShadowNode>;

} // namespace react
} // namespace facebook

0 comments on commit cc09d21

Please sign in to comment.