BREAKING - Change aspect ratio to always be width/height
Summary: @public Aspect ratio being defined as width/height or height/width depending on the situation it was used in turned out to be very confusing. This diff makes aspect ratio always be defined as width/height irregardless of the usage. Differential Revision: D4339132 fbshipit-source-id: e5da32750b55ddaf6acaf1cbd7662d86f2b480c3
This commit is contained in:
committed by
Facebook Github Bot
parent
3d10ba5f72
commit
071f576db9
@@ -351,7 +351,7 @@ TEST(YogaTest, aspect_ratio_double_main) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeStyleSetWidth(root_child0, 50);
|
YGNodeStyleSetWidth(root_child0, 50);
|
||||||
YGNodeStyleSetAspectRatio(root_child0, 2);
|
YGNodeStyleSetAspectRatio(root_child0, 0.5);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -372,7 +372,7 @@ TEST(YogaTest, aspect_ratio_half_main) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeStyleSetWidth(root_child0, 100);
|
YGNodeStyleSetWidth(root_child0, 100);
|
||||||
YGNodeStyleSetAspectRatio(root_child0, 0.5);
|
YGNodeStyleSetAspectRatio(root_child0, 2);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
@@ -1062,7 +1062,7 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
|
|||||||
if (!YGValueIsUndefined(child->style.aspectRatio)) {
|
if (!YGValueIsUndefined(child->style.aspectRatio)) {
|
||||||
if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) {
|
if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) {
|
||||||
child->layout.computedFlexBasis =
|
child->layout.computedFlexBasis =
|
||||||
fmaxf(childWidth * child->style.aspectRatio,
|
fmaxf(childWidth / child->style.aspectRatio,
|
||||||
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn));
|
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn));
|
||||||
return;
|
return;
|
||||||
} else if (isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) {
|
} else if (isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) {
|
||||||
@@ -1157,7 +1157,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
|
|||||||
childWidth = fmaxf(childHeight * child->style.aspectRatio,
|
childWidth = fmaxf(childHeight * child->style.aspectRatio,
|
||||||
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn));
|
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn));
|
||||||
} else if (YGValueIsUndefined(childHeight)) {
|
} else if (YGValueIsUndefined(childHeight)) {
|
||||||
childHeight = fmaxf(childWidth * child->style.aspectRatio,
|
childHeight = fmaxf(childWidth / child->style.aspectRatio,
|
||||||
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow));
|
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1880,7 +1880,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
if (!YGValueIsUndefined(currentRelativeChild->style.aspectRatio)) {
|
if (!YGValueIsUndefined(currentRelativeChild->style.aspectRatio)) {
|
||||||
if (isMainAxisRow && childHeightMeasureMode != YGMeasureModeExactly) {
|
if (isMainAxisRow && childHeightMeasureMode != YGMeasureModeExactly) {
|
||||||
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) {
|
} else if (!isMainAxisRow && childWidthMeasureMode != YGMeasureModeExactly) {
|
||||||
|
@@ -151,6 +151,9 @@ YG_NODE_STYLE_PROPERTY(float, MaxHeight, maxHeight);
|
|||||||
|
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
// Aspect ratio control the size of the undefined dimension of a node.
|
// Aspect ratio control the size of the undefined dimension of a node.
|
||||||
|
// Aspect ratio is encoded as a floating point value width/height. e.g. A value of 2 leads to a node
|
||||||
|
// with a width twice the size of its height while a value of 0.5 gives the opposite effect.
|
||||||
|
//
|
||||||
// - On a node with a set width/height aspect ratio control the size of the unset dimension
|
// - On a node with a set width/height aspect ratio control the size of the unset dimension
|
||||||
// - On a node with a set flex basis aspect ratio controls the size of the node in the cross axis if
|
// - On a node with a set flex basis aspect ratio controls the size of the node in the cross axis if
|
||||||
// unset
|
// unset
|
||||||
|
Reference in New Issue
Block a user