Remove usage of Gutters arrays and YGGutter as index (#1406)

Summary:
X-link: https://github.com/facebook/react-native/pull/39597

Pull Request resolved: https://github.com/facebook/yoga/pull/1406

Similar in vain to D49362819, we want to stop exposing pre-resolved CompactValue, and allow enum class usage without becoming annoying.

This also simplifies gap resolution a bit. I moved this to Style, to make it clear we aren't relying on any node state. I plan to do some similar cleanup for other resolution later.

Reviewed By: rshest

Differential Revision: D49530923

fbshipit-source-id: 47b06a7301fb283acc493dba159f496159d59580
This commit is contained in:
Nick Gerleman
2023-10-03 10:08:10 -07:00
committed by Facebook GitHub Bot
parent 07cabca526
commit 4ef28bce24
7 changed files with 39 additions and 63 deletions

View File

@@ -89,30 +89,6 @@ CompactValue Node::computeEdgeValueForColumn(
}
}
CompactValue Node::computeRowGap(
const Style::Gutters& gutters,
CompactValue defaultValue) {
if (!gutters[YGGutterRow].isUndefined()) {
return gutters[YGGutterRow];
} else if (!gutters[YGGutterAll].isUndefined()) {
return gutters[YGGutterAll];
} else {
return defaultValue;
}
}
CompactValue Node::computeColumnGap(
const Style::Gutters& gutters,
CompactValue defaultValue) {
if (!gutters[YGGutterColumn].isUndefined()) {
return gutters[YGGutterColumn];
} else if (!gutters[YGGutterAll].isUndefined()) {
return gutters[YGGutterAll];
} else {
return defaultValue;
}
}
FloatOptional Node::getLeadingPosition(
const FlexDirection axis,
const float axisSize) const {
@@ -202,13 +178,12 @@ FloatOptional Node::getMarginForAxis(
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
}
float Node::getGapForAxis(const FlexDirection axis, const float widthSize)
const {
auto gap = isRow(axis)
? computeColumnGap(style_.gap(), CompactValue::ofUndefined())
: computeRowGap(style_.gap(), CompactValue::ofUndefined());
auto resolvedGap = yoga::resolveValue(gap, widthSize);
return maxOrDefined(resolvedGap.unwrap(), 0);
float Node::getGapForAxis(const FlexDirection axis) const {
auto gap = isRow(axis) ? style_.resolveColumnGap() : style_.resolveRowGap();
// TODO: Validate percentage gap, and expose ability to set percentage to
// public API
auto resolvedGap = yoga::resolveValue(gap, 0.0f /*ownerSize*/);
return maxOrDefined(resolvedGap.unwrap(), 0.0f);
}
YGSize Node::measure(