Fabric: LayoutableShadowNode::getRelativeLayoutMetrics()

Summary:
The generic method that returns relative (to some specified node) layout metrics.
We need this as a building block to implement `UIManager.measure*()` methods family.

Reviewed By: mdvacca

Differential Revision: D12932549

fbshipit-source-id: 79064551d32b0cd40e72dc87d0ed194e3779ba29
This commit is contained in:
Valentin Shergin 2018-11-21 17:10:30 -08:00 committed by Facebook Github Bot
parent 3ecf4eaccb
commit 9eec2c33e6
2 changed files with 36 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include <react/core/LayoutConstraints.h> #include <react/core/LayoutConstraints.h>
#include <react/core/LayoutContext.h> #include <react/core/LayoutContext.h>
#include <react/core/LayoutMetrics.h> #include <react/core/LayoutMetrics.h>
#include <react/core/ShadowNode.h>
#include <react/debug/DebugStringConvertibleItem.h> #include <react/debug/DebugStringConvertibleItem.h>
#include <react/graphics/conversions.h> #include <react/graphics/conversions.h>
@ -35,6 +36,35 @@ bool LayoutableShadowNode::LayoutableShadowNode::isLayoutOnly() const {
return false; return false;
} }
LayoutMetrics LayoutableShadowNode::getRelativeLayoutMetrics(
const LayoutableShadowNode &ancestorLayoutableShadowNode) const {
std::vector<std::reference_wrapper<const ShadowNode>> ancestors;
auto &ancestorShadowNode =
dynamic_cast<const ShadowNode &>(ancestorLayoutableShadowNode);
auto &shadowNode = dynamic_cast<const ShadowNode &>(*this);
if (!shadowNode.constructAncestorPath(ancestorShadowNode, ancestors)) {
return EmptyLayoutMetrics;
}
auto layoutMetrics = getLayoutMetrics();
for (const auto &currentShadowNode : ancestors) {
auto layoutableCurrentShadowNode =
dynamic_cast<const LayoutableShadowNode *>(&currentShadowNode.get());
if (!layoutableCurrentShadowNode) {
return EmptyLayoutMetrics;
}
layoutMetrics.frame.origin +=
layoutableCurrentShadowNode->getLayoutMetrics().frame.origin;
}
return layoutMetrics;
}
void LayoutableShadowNode::cleanLayout() { void LayoutableShadowNode::cleanLayout() {
isLayoutClean_ = true; isLayoutClean_ = true;
} }

View File

@ -59,6 +59,12 @@ class LayoutableShadowNode : public virtual Sealable {
*/ */
virtual bool isLayoutOnly() const; virtual bool isLayoutOnly() const;
/*
* Returns layout metrics relatively to the given ancestor node.
*/
LayoutMetrics getRelativeLayoutMetrics(
const LayoutableShadowNode &ancestorLayoutableShadowNode) const;
protected: protected:
/* /*
* Clean or Dirty layout state: * Clean or Dirty layout state: