mirror of
https://github.com/status-im/react-native.git
synced 2025-02-22 22:28:09 +00:00
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:
parent
3ecf4eaccb
commit
9eec2c33e6
@ -10,6 +10,7 @@
|
||||
#include <react/core/LayoutConstraints.h>
|
||||
#include <react/core/LayoutContext.h>
|
||||
#include <react/core/LayoutMetrics.h>
|
||||
#include <react/core/ShadowNode.h>
|
||||
#include <react/debug/DebugStringConvertibleItem.h>
|
||||
#include <react/graphics/conversions.h>
|
||||
|
||||
@ -35,6 +36,35 @@ bool LayoutableShadowNode::LayoutableShadowNode::isLayoutOnly() const {
|
||||
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 ¤tShadowNode : ancestors) {
|
||||
auto layoutableCurrentShadowNode =
|
||||
dynamic_cast<const LayoutableShadowNode *>(¤tShadowNode.get());
|
||||
|
||||
if (!layoutableCurrentShadowNode) {
|
||||
return EmptyLayoutMetrics;
|
||||
}
|
||||
|
||||
layoutMetrics.frame.origin +=
|
||||
layoutableCurrentShadowNode->getLayoutMetrics().frame.origin;
|
||||
}
|
||||
|
||||
return layoutMetrics;
|
||||
}
|
||||
|
||||
void LayoutableShadowNode::cleanLayout() {
|
||||
isLayoutClean_ = true;
|
||||
}
|
||||
|
@ -59,6 +59,12 @@ class LayoutableShadowNode : public virtual Sealable {
|
||||
*/
|
||||
virtual bool isLayoutOnly() const;
|
||||
|
||||
/*
|
||||
* Returns layout metrics relatively to the given ancestor node.
|
||||
*/
|
||||
LayoutMetrics getRelativeLayoutMetrics(
|
||||
const LayoutableShadowNode &ancestorLayoutableShadowNode) const;
|
||||
|
||||
protected:
|
||||
/*
|
||||
* Clean or Dirty layout state:
|
||||
|
Loading…
x
Reference in New Issue
Block a user