Skip to content

Commit

Permalink
Fix style resolution functions returning FloatOptional (facebook#39595)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#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.

Differential Revision: D49531421

fbshipit-source-id: 4f38d5e205d2356faf8bd456667a2f3c520d0728
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 28, 2023
1 parent 9bdb11d commit f7fd6fa
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ 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 @@ -47,7 +47,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 f7fd6fa

Please sign in to comment.