mirror of
https://github.com/status-im/react-native.git
synced 2025-02-27 08:30:34 +00:00
BREAKING - Increase priority of AspectRatio to override flex, align stretch, and fixed sizes if specified.
Summary: AspectRatio is a new addition and soon after introduction we noticed use cases which is did not support. Specifically we wanted to support a node being as large as possible within a container while maintaining an arbitrary aspect ratio. This was not possible due to the low priority of AspectRatio, by increasing the priority of AspectRatio this is now possible as FlexGrow will grow an item to fit its parent unless the AspectRatio makes it too big in the cross axis, the AspectRatio will now override the FlexGrow in the main axis in that case. Differential Revision: D4346720 fbshipit-source-id: 1f15613604190e3ad5ff4a467ba57db4bcfd2741
This commit is contained in:
parent
710391597b
commit
b8e79d171a
@ -1878,16 +1878,22 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!YGValueIsUndefined(currentRelativeChild->style.aspectRatio)) {
|
if (!YGValueIsUndefined(currentRelativeChild->style.aspectRatio)) {
|
||||||
if (isMainAxisRow && childHeightMeasureMode != YGMeasureModeExactly) {
|
if (isMainAxisRow) {
|
||||||
childHeight =
|
childHeight =
|
||||||
fmaxf(childWidth / currentRelativeChild->style.aspectRatio,
|
fmaxf(childWidth / currentRelativeChild->style.aspectRatio,
|
||||||
YGNodePaddingAndBorderForAxis(currentRelativeChild, YGFlexDirectionColumn));
|
YGNodePaddingAndBorderForAxis(currentRelativeChild, YGFlexDirectionColumn));
|
||||||
childHeightMeasureMode = YGMeasureModeExactly;
|
childHeightMeasureMode = YGMeasureModeExactly;
|
||||||
} else if (!isMainAxisRow && childWidthMeasureMode != YGMeasureModeExactly) {
|
|
||||||
|
childHeight = fminf(childHeight, availableInnerHeight);
|
||||||
|
childWidth = childHeight * currentRelativeChild->style.aspectRatio;
|
||||||
|
} else {
|
||||||
childWidth =
|
childWidth =
|
||||||
fmaxf(childHeight * currentRelativeChild->style.aspectRatio,
|
fmaxf(childHeight * currentRelativeChild->style.aspectRatio,
|
||||||
YGNodePaddingAndBorderForAxis(currentRelativeChild, YGFlexDirectionRow));
|
YGNodePaddingAndBorderForAxis(currentRelativeChild, YGFlexDirectionRow));
|
||||||
childWidthMeasureMode = YGMeasureModeExactly;
|
childWidthMeasureMode = YGMeasureModeExactly;
|
||||||
|
|
||||||
|
childWidth = fminf(childWidth, availableInnerWidth);
|
||||||
|
childHeight = childWidth / currentRelativeChild->style.aspectRatio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2080,13 +2086,23 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
YGMeasureMode childHeightMeasureMode = YGMeasureModeExactly;
|
YGMeasureMode childHeightMeasureMode = YGMeasureModeExactly;
|
||||||
|
|
||||||
if (isMainAxisRow) {
|
if (isMainAxisRow) {
|
||||||
childHeight = crossDim;
|
|
||||||
childWidth = child->layout.measuredDimensions[YGDimensionWidth] +
|
childWidth = child->layout.measuredDimensions[YGDimensionWidth] +
|
||||||
YGNodeMarginForAxis(child, YGFlexDirectionRow);
|
YGNodeMarginForAxis(child, YGFlexDirectionRow);
|
||||||
|
|
||||||
|
if (!YGValueIsUndefined(child->style.aspectRatio)) {
|
||||||
|
childHeight = childWidth / child->style.aspectRatio;
|
||||||
|
} else {
|
||||||
|
childHeight = crossDim;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
childWidth = crossDim;
|
|
||||||
childHeight = child->layout.measuredDimensions[YGDimensionHeight] +
|
childHeight = child->layout.measuredDimensions[YGDimensionHeight] +
|
||||||
YGNodeMarginForAxis(child, YGFlexDirectionColumn);
|
YGNodeMarginForAxis(child, YGFlexDirectionColumn);
|
||||||
|
|
||||||
|
if (!YGValueIsUndefined(child->style.aspectRatio)) {
|
||||||
|
childWidth = childHeight * child->style.aspectRatio;
|
||||||
|
} else {
|
||||||
|
childWidth = crossDim;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGConstrainMaxSizeForMode(child->style.maxDimensions[YGDimensionWidth],
|
YGConstrainMaxSizeForMode(child->style.maxDimensions[YGDimensionWidth],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user