Summary: X-link: https://github.com/facebook/react-native/pull/39538 Pull Request resolved: https://github.com/facebook/yoga/pull/1399 Moves internal usages of YGPositionType to PositionType bypass-github-export-checks Changelog: [Internal] Reviewed By: rshest Differential Revision: D49361677 fbshipit-source-id: 526222d6cf9f3dc26eddfbfb8a04de4ba28e14a9
83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <yoga/Yoga.h>
|
|
|
|
#include <yoga/algorithm/Align.h>
|
|
#include <yoga/algorithm/Baseline.h>
|
|
#include <yoga/debug/AssertFatal.h>
|
|
#include <yoga/event/event.h>
|
|
|
|
namespace facebook::yoga {
|
|
|
|
float calculateBaseline(const yoga::Node* node) {
|
|
if (node->hasBaselineFunc()) {
|
|
Event::publish<Event::NodeBaselineStart>(node);
|
|
|
|
const float baseline = node->baseline(
|
|
node->getLayout().measuredDimensions[YGDimensionWidth],
|
|
node->getLayout().measuredDimensions[YGDimensionHeight]);
|
|
|
|
Event::publish<Event::NodeBaselineEnd>(node);
|
|
|
|
yoga::assertFatalWithNode(
|
|
node,
|
|
!std::isnan(baseline),
|
|
"Expect custom baseline function to not return NaN");
|
|
return baseline;
|
|
}
|
|
|
|
yoga::Node* baselineChild = nullptr;
|
|
const size_t childCount = node->getChildCount();
|
|
for (size_t i = 0; i < childCount; i++) {
|
|
auto child = node->getChild(i);
|
|
if (child->getLineIndex() > 0) {
|
|
break;
|
|
}
|
|
if (child->getStyle().positionType() == PositionType::Absolute) {
|
|
continue;
|
|
}
|
|
if (resolveChildAlignment(node, child) == Align::Baseline ||
|
|
child->isReferenceBaseline()) {
|
|
baselineChild = child;
|
|
break;
|
|
}
|
|
|
|
if (baselineChild == nullptr) {
|
|
baselineChild = child;
|
|
}
|
|
}
|
|
|
|
if (baselineChild == nullptr) {
|
|
return node->getLayout().measuredDimensions[YGDimensionHeight];
|
|
}
|
|
|
|
const float baseline = calculateBaseline(baselineChild);
|
|
return baseline + baselineChild->getLayout().position[YGEdgeTop];
|
|
}
|
|
|
|
bool isBaselineLayout(const yoga::Node* node) {
|
|
if (isColumn(node->getStyle().flexDirection())) {
|
|
return false;
|
|
}
|
|
if (node->getStyle().alignItems() == Align::Baseline) {
|
|
return true;
|
|
}
|
|
const auto childCount = node->getChildCount();
|
|
for (size_t i = 0; i < childCount; i++) {
|
|
auto child = node->getChild(i);
|
|
if (child->getStyle().positionType() != PositionType::Absolute &&
|
|
child->getStyle().alignSelf() == Align::Baseline) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
} // namespace facebook::yoga
|