Skip to content

Commit

Permalink
Fix style resolution functions returning FloatOptional (#39595)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #39595

X-link: facebook/yoga#1404

These functions all ensure their returns are defined, but return FloatOptional anyway, making their callers have to deal with that possibility. Return `float` instead of `FloatOptional`, and do some additional cleanup.

Reviewed By: rshest

Differential Revision: D49531421

fbshipit-source-id: 95b21cade74e501dd54c7b6ca667c8c3859c5dae
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Oct 3, 2023
1 parent 2547832 commit 72d0fed
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ inline float paddingAndBorderForAxis(
const yoga::Node* const node,
const FlexDirection axis,
const float widthSize) {
return (node->getLeadingPaddingAndBorder(axis, widthSize) +
node->getTrailingPaddingAndBorder(axis, widthSize))
.unwrap();
return node->getLeadingPaddingAndBorder(axis, widthSize) +
node->getTrailingPaddingAndBorder(axis, widthSize);
}

inline FloatOptional boundAxisWithinMinAndMax(
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ FlexLine calculateFlexLine(

child->setLineIndex(lineCount);
const float childMarginMainAxis =
child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap();
child->getMarginForAxis(mainAxis, availableInnerWidth);
const float childLeadingGapMainAxis = isFirstElementInLine ? 0.0f : gap;
const float flexBasisWithMinAndMaxConstraints =
boundAxisWithinMinAndMax(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ static void appendEdges(
const std::string& key,
const Style::Edges& edges) {
if (areFourValuesEqual(edges)) {
auto edgeValue = yoga::Node::computeEdgeValueForColumn(
edges, YGEdgeLeft, CompactValue::ofZero());
appendNumberIfNotZero(base, key, edgeValue);
auto edgeValue = yoga::Node::computeEdgeValueForColumn(edges, YGEdgeLeft);
appendNumberIfNotUndefined(base, key, edgeValue);
} else {
for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) {
std::string str = key + "-" + YGEdgeToString(static_cast<YGEdge>(edge));
Expand All @@ -109,10 +108,8 @@ static void appendEdgeIfNotUndefined(
const YGEdge edge) {
// TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account
auto value = (edge == YGEdgeLeft || edge == YGEdgeRight)
? yoga::Node::computeEdgeValueForRow(
edges, edge, edge, CompactValue::ofUndefined())
: yoga::Node::computeEdgeValueForColumn(
edges, edge, CompactValue::ofUndefined());
? yoga::Node::computeEdgeValueForRow(edges, edge, edge)
: yoga::Node::computeEdgeValueForColumn(edges, edge);
appendNumberIfNotUndefined(base, str, value);
}

Expand Down
Loading

0 comments on commit 72d0fed

Please sign in to comment.