Change the type of aspect Ratio to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7302651

fbshipit-source-id: 53e3b4c9627207a379f927b1f3485e36a9c70601
This commit is contained in:
Pritesh Nandgaonkar 2018-04-03 14:56:29 -07:00 committed by Facebook Github Bot
parent e5a4d59244
commit bcd12f1e87
4 changed files with 47 additions and 30 deletions

View File

@ -95,7 +95,7 @@ void YogaStylableProps::apply(const RawProps &rawProps) {
YOGA_STYLE_PREFIXED_EDGE_PROPERTY(padding)
YOGA_STYLE_PREFIXED_EDGE_PROPERTY(border)
YOGA_STYLE_SIMPLE_FLOAT_PROPERTY(aspectRatio)
YOGA_STYLE_OPTIONAL_FLOAT_PROPERTY(aspectRatio)
}
}
@ -139,7 +139,7 @@ SharedDebugStringConvertibleList YogaStylableProps::getDebugProps() const {
YOGA_STYLE_PROPS_ADD_TO_SET(minSize, minDimensions, , stringFromYogaStyleDimensions)
YOGA_STYLE_PROPS_ADD_TO_SET(maxSize, maxDimensions, , stringFromYogaStyleDimensions)
YOGA_STYLE_PROPS_ADD_TO_SET(aspectRatio, aspectRatio, , folly::to<std::string>)
YOGA_STYLE_PROPS_ADD_TO_SET(aspectRatio, aspectRatio, , stringFromYogaStyleOptionalFloat)
return list;
}

View File

@ -50,7 +50,7 @@ YGStyle::YGStyle()
dimensions(kYGDefaultDimensionValuesAutoUnit),
minDimensions(kYGDefaultDimensionValuesUnit),
maxDimensions(kYGDefaultDimensionValuesUnit),
aspectRatio(YGUndefined) {}
aspectRatio(YGFloatOptional()) {}
// Yoga specific properties, not compatible with flexbox specification
bool YGStyle::operator==(const YGStyle& style) {
@ -91,10 +91,9 @@ bool YGStyle::operator==(const YGStyle& style) {
flexShrink.getValue() == style.flexShrink.getValue();
}
if (!(YGFloatIsUndefined(aspectRatio) &&
YGFloatIsUndefined(style.aspectRatio))) {
areNonFloatValuesEqual =
areNonFloatValuesEqual && aspectRatio == style.aspectRatio;
if (!(aspectRatio.isUndefined() && style.aspectRatio.isUndefined())) {
areNonFloatValuesEqual = areNonFloatValuesEqual &&
aspectRatio.getValue() == style.aspectRatio.getValue();
}
return areNonFloatValuesEqual;

View File

@ -32,7 +32,7 @@ struct YGStyle {
std::array<YGValue, 2> dimensions;
std::array<YGValue, 2> minDimensions;
std::array<YGValue, 2> maxDimensions;
float aspectRatio;
YGFloatOptional aspectRatio;
YGStyle();
// Yoga specific properties, not compatible with flexbox specification

View File

@ -930,16 +930,30 @@ float YGNodeStyleGetBorder(const YGNodeRef node, const YGEdge edge) {
return node->getStyle().border[edge].value;
}
// Yoga specific properties, not compatible with flexbox specification
// TODO(T26792433): Change the API to accept YGFloatOptional.
float YGNodeStyleGetAspectRatio(const YGNodeRef node) {
const YGFloatOptional op = node->getStyle().aspectRatio;
return op.isUndefined() ? YGUndefined : op.getValue();
}
// TODO(T26792433): Change the API to accept YGFloatOptional.
void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) {
if (!YGFloatOptionalFloatEquals(node->getStyle().aspectRatio, aspectRatio)) {
YGStyle style = node->getStyle();
style.aspectRatio = YGFloatOptional(aspectRatio);
node->setStyle(style);
node->markDirtyAndPropogate();
}
}
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Width, width, dimensions[YGDimensionWidth]);
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Height, height, dimensions[YGDimensionHeight]);
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MinWidth, minWidth, minDimensions[YGDimensionWidth]);
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MinHeight, minHeight, minDimensions[YGDimensionHeight]);
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MaxWidth, maxWidth, maxDimensions[YGDimensionWidth]);
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MaxHeight, maxHeight, maxDimensions[YGDimensionHeight]);
// Yoga specific properties, not compatible with flexbox specification
YG_NODE_STYLE_PROPERTY_IMPL(float, AspectRatio, aspectRatio, aspectRatio);
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Left, position[YGEdgeLeft]);
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Top, position[YGEdgeTop]);
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Right, position[YGEdgeRight]);
@ -1278,14 +1292,15 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
}
}
if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) {
if (!child->getStyle().aspectRatio.isUndefined()) {
if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) {
childHeight = marginColumn +
(childWidth - marginRow) / child->getStyle().aspectRatio;
(childWidth - marginRow) / child->getStyle().aspectRatio.getValue();
childHeightMeasureMode = YGMeasureModeExactly;
} else if (isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) {
childWidth = marginRow +
(childHeight - marginColumn) * child->getStyle().aspectRatio;
(childHeight - marginColumn) *
child->getStyle().aspectRatio.getValue();
childWidthMeasureMode = YGMeasureModeExactly;
}
}
@ -1300,8 +1315,9 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth && childWidthStretch) {
childWidth = width;
childWidthMeasureMode = YGMeasureModeExactly;
if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) {
childHeight = (childWidth - marginRow) / child->getStyle().aspectRatio;
if (!child->getStyle().aspectRatio.isUndefined()) {
childHeight =
(childWidth - marginRow) / child->getStyle().aspectRatio.getValue();
childHeightMeasureMode = YGMeasureModeExactly;
}
}
@ -1313,9 +1329,9 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
childHeight = height;
childHeightMeasureMode = YGMeasureModeExactly;
if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) {
childWidth =
(childHeight - marginColumn) * child->getStyle().aspectRatio;
if (!child->getStyle().aspectRatio.isUndefined()) {
childWidth = (childHeight - marginColumn) *
child->getStyle().aspectRatio.getValue();
childWidthMeasureMode = YGMeasureModeExactly;
}
}
@ -1411,13 +1427,14 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
// Exactly one dimension needs to be defined for us to be able to do aspect ratio
// calculation. One dimension being the anchor and the other being flexible.
if (YGFloatIsUndefined(childWidth) ^ YGFloatIsUndefined(childHeight)) {
if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) {
if (!child->getStyle().aspectRatio.isUndefined()) {
if (YGFloatIsUndefined(childWidth)) {
childWidth = marginRow +
(childHeight - marginColumn) * child->getStyle().aspectRatio;
(childHeight - marginColumn) *
child->getStyle().aspectRatio.getValue();
} else if (YGFloatIsUndefined(childHeight)) {
childHeight = marginColumn +
(childWidth - marginRow) / child->getStyle().aspectRatio;
(childWidth - marginRow) / child->getStyle().aspectRatio.getValue();
}
}
}
@ -1997,11 +2014,11 @@ static float YGDistributeFreeSpaceSecondPass(
YGMeasureMode childCrossMeasureMode;
YGMeasureMode childMainMeasureMode = YGMeasureModeExactly;
if (!YGFloatIsUndefined(currentRelativeChild->getStyle().aspectRatio)) {
if (!currentRelativeChild->getStyle().aspectRatio.isUndefined()) {
childCrossSize = isMainAxisRow ? (childMainSize - marginMain) /
currentRelativeChild->getStyle().aspectRatio
currentRelativeChild->getStyle().aspectRatio.getValue()
: (childMainSize - marginMain) *
currentRelativeChild->getStyle().aspectRatio;
currentRelativeChild->getStyle().aspectRatio.getValue();
childCrossMeasureMode = YGMeasureModeExactly;
childCrossSize += marginCross;
@ -2889,11 +2906,12 @@ static void YGNodelayoutImpl(const YGNodeRef node,
float childMainSize =
child->getLayout().measuredDimensions[dim[mainAxis]];
float childCrossSize =
!YGFloatIsUndefined(child->getStyle().aspectRatio)
!child->getStyle().aspectRatio.isUndefined()
? ((child->getMarginForAxis(crossAxis, availableInnerWidth) +
(isMainAxisRow
? childMainSize / child->getStyle().aspectRatio
: childMainSize * child->getStyle().aspectRatio)))
(isMainAxisRow ? childMainSize /
child->getStyle().aspectRatio.getValue()
: childMainSize *
child->getStyle().aspectRatio.getValue())))
: collectedFlexItemsValues.crossDim;
childMainSize +=