Skip to content

Commit

Permalink
Fix style resolution functions returning FloatOptional (facebook#1404)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#39595

Pull Request resolved: facebook#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 ce8fe99 commit 2734784
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 343 deletions.
5 changes: 2 additions & 3 deletions yoga/algorithm/BoundAxis.h
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
201 changes: 82 additions & 119 deletions yoga/algorithm/CalculateLayout.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion yoga/algorithm/FlexLine.cpp
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
11 changes: 4 additions & 7 deletions yoga/debug/NodeToString.cpp
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 2734784

Please sign in to comment.