Introducing `LayoutableShadowNode::isLayoutOnly` and (theoretical) view-flattening

Summary:
@public
Voalá, this small change actually implements view flattening. Obviously, it does not work right now because there are no `ShadowNode` classes which implement `isLayoutOnly`.
Surprisingly, correct implementing of `isLayoutOnly` is quite tricky, we will work on this in coming diffs.

Reviewed By: mdvacca

Differential Revision: D9403565

fbshipit-source-id: 1f16f912cb5c6841405a1fc3cf36aec28698c11f
This commit is contained in:
Valentin Shergin 2018-09-03 22:53:26 -07:00 committed by Facebook Github Bot
parent 0792fba63f
commit 1068da2ec7
3 changed files with 30 additions and 5 deletions

View File

@ -31,6 +31,10 @@ bool LayoutableShadowNode::setLayoutMetrics(LayoutMetrics layoutMetrics) {
return true; return true;
} }
bool LayoutableShadowNode::LayoutableShadowNode::isLayoutOnly() const {
return false;
}
void LayoutableShadowNode::cleanLayout() { void LayoutableShadowNode::cleanLayout() {
isLayoutClean_ = true; isLayoutClean_ = true;
} }

View File

@ -52,6 +52,13 @@ public:
*/ */
virtual LayoutMetrics getLayoutMetrics() const; virtual LayoutMetrics getLayoutMetrics() const;
/*
* Returns `true` if the node represents only information necessary for
* layout computation and can be safely removed from view hierarchy.
* Default implementation returns `false`.
*/
virtual bool isLayoutOnly() const;
protected: protected:
/* /*

View File

@ -11,13 +11,27 @@
namespace facebook { namespace facebook {
namespace react { namespace react {
static void sliceChildShadowNodeViewPairsRecursively(ShadowViewNodePairList &pairList, Point layoutOffset, const ShadowNode &shadowNode) {
for (const auto &childShadowNode : shadowNode.getChildren()) {
auto shadowView = ShadowView(*childShadowNode);
const auto layoutableShadowNode = dynamic_cast<const LayoutableShadowNode *>(childShadowNode.get());
if (layoutableShadowNode && layoutableShadowNode->isLayoutOnly()) {
sliceChildShadowNodeViewPairsRecursively(
pairList,
layoutOffset + shadowView.layoutMetrics.frame.origin,
*childShadowNode
);
} else {
shadowView.layoutMetrics.frame.origin += layoutOffset;
pairList.push_back({shadowView, *childShadowNode});
}
}
}
static ShadowViewNodePairList sliceChildShadowNodeViewPairs(const ShadowNode &shadowNode) { static ShadowViewNodePairList sliceChildShadowNodeViewPairs(const ShadowNode &shadowNode) {
ShadowViewNodePairList pairList; ShadowViewNodePairList pairList;
sliceChildShadowNodeViewPairsRecursively(pairList, {0, 0}, shadowNode);
for (const auto &childShadowNode : shadowNode.getChildren()) {
pairList.push_back({ShadowView(*childShadowNode), *childShadowNode});
}
return pairList; return pairList;
} }