Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where absolute children of row-reverse containers would inset on the wrong side #41293

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void appendFloatOptionalIfDefined(
std::string& base,
const std::string key,
const FloatOptional num) {
if (!num.isUndefined()) {
if (num.isDefined()) {
appendFormattedString(base, "%s: %g; ", key.c_str(), num.unwrap());
}
}
Expand Down Expand Up @@ -177,7 +177,7 @@ void nodeToString(
appendEdges(str, "padding", style.padding());
appendEdges(str, "border", style.border());

if (!style.gap(Gutter::All).isUndefined()) {
if (style.gap(Gutter::All).isDefined()) {
appendNumberIfNotUndefined(str, "gap", style.gap(Gutter::All));
} else {
appendNumberIfNotUndefined(str, "column-gap", style.gap(Gutter::Column));
Expand Down
84 changes: 69 additions & 15 deletions packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ CompactValue Node::computeEdgeValueForRow(
const Style::Edges& edges,
YGEdge rowEdge,
YGEdge edge) {
if (!edges[rowEdge].isUndefined()) {
if (edges[rowEdge].isDefined()) {
return edges[rowEdge];
} else if (!edges[edge].isUndefined()) {
} else if (edges[edge].isDefined()) {
return edges[edge];
} else if (!edges[YGEdgeHorizontal].isUndefined()) {
} else if (edges[YGEdgeHorizontal].isDefined()) {
return edges[YGEdgeHorizontal];
} else {
return edges[YGEdgeAll];
Expand All @@ -74,9 +74,9 @@ CompactValue Node::computeEdgeValueForRow(
CompactValue Node::computeEdgeValueForColumn(
const Style::Edges& edges,
YGEdge edge) {
if (!edges[edge].isUndefined()) {
if (edges[edge].isDefined()) {
return edges[edge];
} else if (!edges[YGEdgeVertical].isUndefined()) {
} else if (edges[YGEdgeVertical].isDefined()) {
return edges[YGEdgeVertical];
} else {
return edges[YGEdgeAll];
Expand All @@ -99,14 +99,32 @@ YGEdge Node::getInlineEndEdgeUsingErrata(
: inlineEndEdge(flexDirection, direction);
}

bool Node::isFlexStartPositionDefined(FlexDirection axis) const {
const YGEdge startEdge = flexStartEdge(axis);
auto leadingPosition = isRow(axis)
? computeEdgeValueForRow(style_.position(), YGEdgeStart, startEdge)
: computeEdgeValueForColumn(style_.position(), startEdge);

return leadingPosition.isDefined();
}

bool Node::isInlineStartPositionDefined(FlexDirection axis, Direction direction)
const {
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
auto leadingPosition = isRow(axis)
? computeEdgeValueForRow(style_.position(), YGEdgeStart, startEdge)
: computeEdgeValueForColumn(style_.position(), startEdge);

return !leadingPosition.isUndefined();
return leadingPosition.isDefined();
}

bool Node::isFlexEndPositionDefined(FlexDirection axis) const {
const YGEdge endEdge = flexEndEdge(axis);
auto trailingPosition = isRow(axis)
? computeEdgeValueForRow(style_.position(), YGEdgeEnd, endEdge)
: computeEdgeValueForColumn(style_.position(), endEdge);

return !trailingPosition.isUndefined();
}

bool Node::isInlineEndPositionDefined(FlexDirection axis, Direction direction)
Expand All @@ -116,7 +134,16 @@ bool Node::isInlineEndPositionDefined(FlexDirection axis, Direction direction)
? computeEdgeValueForRow(style_.position(), YGEdgeEnd, endEdge)
: computeEdgeValueForColumn(style_.position(), endEdge);

return !trailingPosition.isUndefined();
return trailingPosition.isDefined();
}

float Node::getFlexStartPosition(FlexDirection axis, float axisSize) const {
const YGEdge startEdge = flexStartEdge(axis);
auto leadingPosition = isRow(axis)
? computeEdgeValueForRow(style_.position(), YGEdgeStart, startEdge)
: computeEdgeValueForColumn(style_.position(), startEdge);

return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f);
}

float Node::getInlineStartPosition(
Expand All @@ -131,6 +158,15 @@ float Node::getInlineStartPosition(
return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f);
}

float Node::getFlexEndPosition(FlexDirection axis, float axisSize) const {
const YGEdge endEdge = flexEndEdge(axis);
auto trailingPosition = isRow(axis)
? computeEdgeValueForRow(style_.position(), YGEdgeEnd, endEdge)
: computeEdgeValueForColumn(style_.position(), endEdge);

return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f);
}

float Node::getInlineEndPosition(
FlexDirection axis,
Direction direction,
Expand All @@ -143,6 +179,15 @@ float Node::getInlineEndPosition(
return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f);
}

float Node::getFlexStartMargin(FlexDirection axis, float widthSize) const {
const YGEdge startEdge = flexStartEdge(axis);
auto leadingMargin = isRow(axis)
? computeEdgeValueForRow(style_.margin(), YGEdgeStart, startEdge)
: computeEdgeValueForColumn(style_.margin(), startEdge);

return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f);
}

float Node::getInlineStartMargin(
FlexDirection axis,
Direction direction,
Expand All @@ -155,6 +200,15 @@ float Node::getInlineStartMargin(
return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f);
}

float Node::getFlexEndMargin(FlexDirection axis, float widthSize) const {
const YGEdge endEdge = flexEndEdge(axis);
auto trailingMargin = isRow(axis)
? computeEdgeValueForRow(style_.margin(), YGEdgeEnd, endEdge)
: computeEdgeValueForColumn(style_.margin(), endEdge);

return resolveValue(trailingMargin, widthSize).unwrapOrDefault(0.0f);
}

float Node::getInlineEndMargin(
FlexDirection axis,
Direction direction,
Expand Down Expand Up @@ -511,15 +565,15 @@ void Node::setPosition(
}

YGValue Node::getFlexStartMarginValue(FlexDirection axis) const {
if (isRow(axis) && !style_.margin()[YGEdgeStart].isUndefined()) {
if (isRow(axis) && style_.margin()[YGEdgeStart].isDefined()) {
return style_.margin()[YGEdgeStart];
} else {
return style_.margin()[flexStartEdge(axis)];
}
}

YGValue Node::marginTrailingValue(FlexDirection axis) const {
if (isRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) {
if (isRow(axis) && style_.margin()[YGEdgeEnd].isDefined()) {
return style_.margin()[YGEdgeEnd];
} else {
return style_.margin()[flexEndEdge(axis)];
Expand All @@ -531,7 +585,7 @@ YGValue Node::resolveFlexBasisPtr() const {
if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) {
return flexBasis;
}
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) {
if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) {
return config_->useWebDefaults() ? YGValueAuto : YGValueZero;
}
return YGValueAuto;
Expand All @@ -540,7 +594,7 @@ YGValue Node::resolveFlexBasisPtr() const {
void Node::resolveDimension() {
const Style& style = getStyle();
for (auto dim : {Dimension::Width, Dimension::Height}) {
if (!style.maxDimension(dim).isUndefined() &&
if (style.maxDimension(dim).isDefined() &&
yoga::inexactEquals(style.maxDimension(dim), style.minDimension(dim))) {
resolvedDimensions_[yoga::to_underlying(dim)] = style.maxDimension(dim);
} else {
Expand Down Expand Up @@ -598,10 +652,10 @@ float Node::resolveFlexGrow() const {
if (owner_ == nullptr) {
return 0.0;
}
if (!style_.flexGrow().isUndefined()) {
if (style_.flexGrow().isDefined()) {
return style_.flexGrow().unwrap();
}
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) {
if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) {
return style_.flex().unwrap();
}
return Style::DefaultFlexGrow;
Expand All @@ -611,10 +665,10 @@ float Node::resolveFlexShrink() const {
if (owner_ == nullptr) {
return 0.0;
}
if (!style_.flexShrink().isUndefined()) {
if (style_.flexShrink().isDefined()) {
return style_.flexShrink().unwrap();
}
if (!config_->useWebDefaults() && !style_.flex().isUndefined() &&
if (!config_->useWebDefaults() && style_.flex().isDefined() &&
style_.flex().unwrap() < 0.0f) {
return -style_.flex().unwrap();
}
Expand Down
6 changes: 6 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,28 @@ class YG_EXPORT Node : public ::YGNode {
YGEdge edge);

// Methods related to positions, margin, padding and border
bool isFlexStartPositionDefined(FlexDirection axis) const;
bool isInlineStartPositionDefined(FlexDirection axis, Direction direction)
const;
bool isFlexEndPositionDefined(FlexDirection axis) const;
bool isInlineEndPositionDefined(FlexDirection axis, Direction direction)
const;
float getFlexStartPosition(FlexDirection axis, float axisSize) const;
float getInlineStartPosition(
FlexDirection axis,
Direction direction,
float axisSize) const;
float getFlexEndPosition(FlexDirection axis, float axisSize) const;
float getInlineEndPosition(
FlexDirection axis,
Direction direction,
float axisSize) const;
float getFlexStartMargin(FlexDirection axis, float widthSize) const;
float getInlineStartMargin(
FlexDirection axis,
Direction direction,
float widthSize) const;
float getFlexEndMargin(FlexDirection axis, float widthSize) const;
float getInlineEndMargin(
FlexDirection axis,
Direction direction,
Expand Down
12 changes: 8 additions & 4 deletions packages/react-native/ReactCommon/yoga/yoga/numeric/Comparison.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ constexpr bool isUndefined(auto value) {
return value != value;
}

constexpr bool isDefined(auto value) {
return !isUndefined(value);
}

constexpr auto maxOrDefined(auto a, auto b) {
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
if (yoga::isDefined(a) && yoga::isDefined(b)) {
return std::max(a, b);
}
return yoga::isUndefined(a) ? b : a;
}

constexpr auto minOrDefined(auto a, auto b) {
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
if (yoga::isDefined(a) && yoga::isDefined(b)) {
return std::min(a, b);
}

Expand All @@ -37,14 +41,14 @@ constexpr auto minOrDefined(auto a, auto b) {
// Custom equality functions using a hardcoded epsilon of 0.0001f, or returning
// true if both floats are NaN.
inline bool inexactEquals(float a, float b) {
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
if (yoga::isDefined(a) && yoga::isDefined(b)) {
return std::abs(a - b) < 0.0001f;
}
return yoga::isUndefined(a) && yoga::isUndefined(b);
}

inline bool inexactEquals(double a, double b) {
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
if (yoga::isDefined(a) && yoga::isDefined(b)) {
return std::abs(a - b) < 0.0001;
}
return yoga::isUndefined(a) && yoga::isUndefined(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ struct FloatOptional {
constexpr bool isUndefined() const {
return yoga::isUndefined(value_);
}

constexpr bool isDefined() const {
return yoga::isDefined(value_);
}
};

// operators take FloatOptional by value, as it is a 32bit value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ class YG_EXPORT CompactValue {
repr_ != ZERO_BITS_PERCENT && std::isnan(yoga::bit_cast<float>(repr_)));
}

bool isDefined() const noexcept {
return !isUndefined();
}

bool isAuto() const noexcept {
return repr_ == AUTO_BITS;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/style/Style.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,15 @@ class YG_EXPORT Style {
}

CompactValue resolveColumnGap() const {
if (!gap_[yoga::to_underlying(Gutter::Column)].isUndefined()) {
if (gap_[yoga::to_underlying(Gutter::Column)].isDefined()) {
return gap_[yoga::to_underlying(Gutter::Column)];
} else {
return gap_[yoga::to_underlying(Gutter::All)];
}
}

CompactValue resolveRowGap() const {
if (!gap_[yoga::to_underlying(Gutter::Row)].isUndefined()) {
if (gap_[yoga::to_underlying(Gutter::Row)].isDefined()) {
return gap_[yoga::to_underlying(Gutter::Row)];
} else {
return gap_[yoga::to_underlying(Gutter::All)];
Expand Down
Loading