Fabric: Simplifying usage of ConcreteComponentDescriptor

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
This commit is contained in:
Valentin Shergin 2018-05-17 20:03:46 -07:00 committed by Facebook Github Bot
parent 8f507280ac
commit cc09d21e60
6 changed files with 19 additions and 32 deletions

View File

@ -35,6 +35,21 @@ public:
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,

View File

@ -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

View File

@ -27,10 +27,6 @@ public:
textLayoutManager_ = std::make_shared<TextLayoutManager>();
}
ComponentName getComponentName() const override {
return "Paragraph";
}
void adopt(UnsharedShadowNode shadowNode) const override {
ConcreteComponentDescriptor<ParagraphShadowNode>::adopt(shadowNode);

View File

@ -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

View File

@ -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

View File

@ -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