Summary: X-link: https://github.com/facebook/react-native/pull/41391 Pull Request resolved: https://github.com/facebook/yoga/pull/1461 Converts usages of `YGEdge` within internal APIs to `yoga::Edge` scoped enum. With the exception of YGUnit which is in its own state of transition, this is the last public yoga enum to need to be moved to scoped enum form for usages internal to the Yoga public API. Changelog: [internal] Reviewed By: rshest Differential Revision: D51152779 fbshipit-source-id: 06554f67bfd7709cbc24fdd9a5474e897e9e95d8
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().measuredDimension(Dimension::Width),
|
|
node->getLayout().measuredDimension(Dimension::Height));
|
|
|
|
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().measuredDimension(Dimension::Height);
|
|
}
|
|
|
|
const float baseline = calculateBaseline(baselineChild);
|
|
return baseline + baselineChild->getLayout().position(Edge::Top);
|
|
}
|
|
|
|
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
|