mirror of
https://github.com/status-im/react-native.git
synced 2025-01-11 18:14:14 +00:00
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:
parent
8f507280ac
commit
cc09d21e60
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user