Skip to content

Commit

Permalink
Import "Fix percent absolute position and size calcuate different wit…
Browse files Browse the repository at this point in the history
…h web" behind experimental feature (#1028) (#1201)

Summary:
Fixes facebook/yoga#850

facebook/yoga#850 describes a conformance issue where positioning of an absolute child using percentages is not calculated against the correct box size.

This takes the fix for that in facebook/yoga#1028, regenerates tests, and fixes tests so that the experimental feature can be enabled. Goal is to run this as an experiment internally to see if we can enable by default.

Changelog:
[Internal]

X-link: facebook/yoga#1201

Reviewed By: yungsters

Differential Revision: D42282358

Pulled By: NickGerleman

fbshipit-source-id: 57c0dd9b0f1c47cb9335ff6e13d44b4646e5fa58
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Jan 8, 2023
1 parent ac66512 commit e55277c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
package com.facebook.yoga;

public enum YogaExperimentalFeature {
WEB_FLEX_BASIS(0);
WEB_FLEX_BASIS(0),
ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE(1),
FIX_ABSOLUTE_TRAILING_COLUMN_MARGIN(2);

private final int mIntValue;

Expand All @@ -25,6 +27,8 @@ public int intValue() {
public static YogaExperimentalFeature fromInt(int value) {
switch (value) {
case 0: return WEB_FLEX_BASIS;
case 1: return ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE;
case 2: return FIX_ABSOLUTE_TRAILING_COLUMN_MARGIN;
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
Expand Down
4 changes: 4 additions & 0 deletions ReactCommon/yoga/yoga/YGEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ const char* YGExperimentalFeatureToString(const YGExperimentalFeature value) {
switch (value) {
case YGExperimentalFeatureWebFlexBasis:
return "web-flex-basis";
case YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge:
return "absolute-percentage-against-padding-edge";
case YGExperimentalFeatureFixAbsoluteTrailingColumnMargin:
return "fix-absolute-trailing-column-margin";
}
return "unknown";
}
Expand Down
4 changes: 3 additions & 1 deletion ReactCommon/yoga/yoga/YGEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ YG_ENUM_SEQ_DECL(

YG_ENUM_SEQ_DECL(
YGExperimentalFeature,
YGExperimentalFeatureWebFlexBasis)
YGExperimentalFeatureWebFlexBasis,
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge,
YGExperimentalFeatureFixAbsoluteTrailingColumnMargin)

YG_ENUM_SEQ_DECL(
YGFlexDirection,
Expand Down
58 changes: 54 additions & 4 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,13 +1595,21 @@ static void YGNodeAbsoluteLayoutChild(
depth,
generationCount);

auto trailingMarginOuterSize =
YGConfigIsExperimentalFeatureEnabled(
node->getConfig(),
YGExperimentalFeatureFixAbsoluteTrailingColumnMargin)
? isMainAxisRow ? height : width
: width;

if (child->isTrailingPosDefined(mainAxis) &&
!child->isLeadingPositionDefined(mainAxis)) {
child->setLayoutPosition(
node->getLayout().measuredDimensions[dim[mainAxis]] -
child->getLayout().measuredDimensions[dim[mainAxis]] -
node->getTrailingBorder(mainAxis) -
child->getTrailingMargin(mainAxis, width).unwrap() -
child->getTrailingMargin(mainAxis, trailingMarginOuterSize)
.unwrap() -
child->getTrailingPosition(mainAxis, isMainAxisRow ? width : height)
.unwrap(),
leading[mainAxis]);
Expand All @@ -1620,6 +1628,22 @@ static void YGNodeAbsoluteLayoutChild(
(node->getLayout().measuredDimensions[dim[mainAxis]] -
child->getLayout().measuredDimensions[dim[mainAxis]]),
leading[mainAxis]);
} else if (
YGConfigIsExperimentalFeatureEnabled(
node->getConfig(),
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) &&
child->isLeadingPositionDefined(mainAxis)) {
child->setLayoutPosition(
child->getLeadingPosition(
mainAxis, node->getLayout().measuredDimensions[dim[mainAxis]])
.unwrap() +
node->getLeadingBorder(mainAxis) +
child
->getLeadingMargin(
mainAxis,
node->getLayout().measuredDimensions[dim[mainAxis]])
.unwrap(),
leading[mainAxis]);
}

if (child->isTrailingPosDefined(crossAxis) &&
Expand All @@ -1628,7 +1652,8 @@ static void YGNodeAbsoluteLayoutChild(
node->getLayout().measuredDimensions[dim[crossAxis]] -
child->getLayout().measuredDimensions[dim[crossAxis]] -
node->getTrailingBorder(crossAxis) -
child->getTrailingMargin(crossAxis, width).unwrap() -
child->getTrailingMargin(crossAxis, trailingMarginOuterSize)
.unwrap() -
child
->getTrailingPosition(crossAxis, isMainAxisRow ? height : width)
.unwrap(),
Expand All @@ -1650,6 +1675,23 @@ static void YGNodeAbsoluteLayoutChild(
(node->getLayout().measuredDimensions[dim[crossAxis]] -
child->getLayout().measuredDimensions[dim[crossAxis]]),
leading[crossAxis]);
} else if (
YGConfigIsExperimentalFeatureEnabled(
node->getConfig(),
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) &&
child->isLeadingPositionDefined(crossAxis)) {
child->setLayoutPosition(
child->getLeadingPosition(
crossAxis,
node->getLayout().measuredDimensions[dim[crossAxis]])
.unwrap() +
node->getLeadingBorder(crossAxis) +
child
->getLeadingMargin(
crossAxis,
node->getLayout().measuredDimensions[dim[crossAxis]])
.unwrap(),
leading[crossAxis]);
}
}

Expand Down Expand Up @@ -3569,9 +3611,17 @@ static void YGNodelayoutImpl(
YGNodeAbsoluteLayoutChild(
node,
child,
availableInnerWidth,
YGConfigIsExperimentalFeatureEnabled(
node->getConfig(),
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge)
? node->getLayout().measuredDimensions[YGDimensionWidth]
: availableInnerWidth,
isMainAxisRow ? measureModeMainDim : measureModeCrossDim,
availableInnerHeight,
YGConfigIsExperimentalFeatureEnabled(
node->getConfig(),
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge)
? node->getLayout().measuredDimensions[YGDimensionHeight]
: availableInnerHeight,
direction,
config,
layoutMarkerData,
Expand Down

0 comments on commit e55277c

Please sign in to comment.