Fabric: Introcucing `ConcreteComponentDescriptor::adopt()`
Summary: Overriding `adopt` method allows subclasses to configure just created or cloned shadow nodes without overriding `create` and `clone` methods. Reviewed By: mdvacca Differential Revision: D7738581 fbshipit-source-id: bfe4e4e2d3d448591a3267b5ea7ca4e0800f5ba0
This commit is contained in:
parent
9f46f425f4
commit
6bbc2ec921
|
@ -41,7 +41,7 @@ public:
|
||||||
const InstanceHandle &instanceHandle,
|
const InstanceHandle &instanceHandle,
|
||||||
const SharedProps &props
|
const SharedProps &props
|
||||||
) const override {
|
) const override {
|
||||||
return std::make_shared<ShadowNodeT>(
|
UnsharedShadowNode shadowNode = std::make_shared<ShadowNodeT>(
|
||||||
tag,
|
tag,
|
||||||
rootTag,
|
rootTag,
|
||||||
instanceHandle,
|
instanceHandle,
|
||||||
|
@ -49,14 +49,19 @@ public:
|
||||||
ShadowNode::emptySharedShadowNodeSharedList(),
|
ShadowNode::emptySharedShadowNodeSharedList(),
|
||||||
getCloneFunction()
|
getCloneFunction()
|
||||||
);
|
);
|
||||||
|
adopt(shadowNode);
|
||||||
|
return shadowNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedShadowNode cloneShadowNode(
|
SharedShadowNode cloneShadowNode(
|
||||||
const SharedShadowNode &shadowNode,
|
const SharedShadowNode &sourceShadowNode,
|
||||||
const SharedProps &props = nullptr,
|
const SharedProps &props = nullptr,
|
||||||
const SharedShadowNodeSharedList &children = nullptr
|
const SharedShadowNodeSharedList &children = nullptr
|
||||||
) const override {
|
) const override {
|
||||||
return std::make_shared<ShadowNodeT>(std::static_pointer_cast<const ShadowNodeT>(shadowNode), std::static_pointer_cast<const ConcreteProps>(props), children);
|
assert(std::dynamic_pointer_cast<const ShadowNodeT>(sourceShadowNode));
|
||||||
|
UnsharedShadowNode shadowNode = std::make_shared<ShadowNodeT>(std::static_pointer_cast<const ShadowNodeT>(sourceShadowNode), std::static_pointer_cast<const ConcreteProps>(props), children);
|
||||||
|
adopt(shadowNode);
|
||||||
|
return shadowNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendChild(
|
void appendChild(
|
||||||
|
@ -75,7 +80,14 @@ public:
|
||||||
return ShadowNodeT::Props(rawProps, props);
|
return ShadowNodeT::Props(rawProps, props);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void adopt(UnsharedShadowNode shadowNode) const {
|
||||||
|
// Default implementation does nothing.
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
mutable ShadowNodeCloneFunction cloneFunction_;
|
mutable ShadowNodeCloneFunction cloneFunction_;
|
||||||
|
|
||||||
ShadowNodeCloneFunction getCloneFunction() const {
|
ShadowNodeCloneFunction getCloneFunction() const {
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
auto concreteBaseProps = std::dynamic_pointer_cast<const PropsT>(baseProps);
|
auto concreteBaseProps = std::dynamic_pointer_cast<const PropsT>(baseProps);
|
||||||
|
assert(concreteBaseProps);
|
||||||
auto props = std::make_shared<PropsT>(*concreteBaseProps);
|
auto props = std::make_shared<PropsT>(*concreteBaseProps);
|
||||||
props->apply(rawProps);
|
props->apply(rawProps);
|
||||||
return props;
|
return props;
|
||||||
|
@ -79,6 +80,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
const SharedConcreteProps getProps() const {
|
const SharedConcreteProps getProps() const {
|
||||||
|
assert(std::dynamic_pointer_cast<const PropsT>(props_));
|
||||||
|
|
||||||
return std::static_pointer_cast<const PropsT>(props_);
|
return std::static_pointer_cast<const PropsT>(props_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace react {
|
||||||
class ShadowNode;
|
class ShadowNode;
|
||||||
|
|
||||||
using SharedShadowNode = std::shared_ptr<const ShadowNode>;
|
using SharedShadowNode = std::shared_ptr<const ShadowNode>;
|
||||||
|
using UnsharedShadowNode = std::shared_ptr<ShadowNode>;
|
||||||
using SharedShadowNodeList = std::vector<std::shared_ptr<const ShadowNode>>;
|
using SharedShadowNodeList = std::vector<std::shared_ptr<const ShadowNode>>;
|
||||||
using SharedShadowNodeSharedList = std::shared_ptr<const SharedShadowNodeList>;
|
using SharedShadowNodeSharedList = std::shared_ptr<const SharedShadowNodeList>;
|
||||||
using SharedShadowNodeUnsharedList = std::shared_ptr<SharedShadowNodeList>;
|
using SharedShadowNodeUnsharedList = std::shared_ptr<SharedShadowNodeList>;
|
||||||
|
|
Loading…
Reference in New Issue