Change the type of flexGrow to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7215355

fbshipit-source-id: 1298ee332551d44e4d070169a1e4103d005c4f43
This commit is contained in:
Pritesh Nandgaonkar 2018-03-14 04:17:11 -07:00 committed by Facebook Github Bot
parent 5b3d59598a
commit 3274e9fa51
5 changed files with 26 additions and 10 deletions

View File

@ -592,8 +592,8 @@ float YGNode::resolveFlexGrow() {
if (parent_ == nullptr) {
return 0.0;
}
if (!YGFloatIsUndefined(style_.flexGrow)) {
return style_.flexGrow;
if (!style_.flexGrow.isUndefined) {
return style_.flexGrow.value;
}
if (!style_.flex.isUndefined && style_.flex.value > 0.0f) {
return style_.flex.value;

View File

@ -161,7 +161,7 @@ void YGNodeToString(
appendFormatedString(
str, "align-self: %s; ", YGAlignToString(node->getStyle().alignSelf));
}
appendFloatIfNotUndefined(str, "flex-grow", node->getStyle().flexGrow);
appendFloatOptionalIfDefined(str, "flex-grow", node->getStyle().flexGrow);
appendFloatIfNotUndefined(str, "flex-shrink", node->getStyle().flexShrink);
appendNumberIfNotAuto(str, "flex-basis", node->getStyle().flexBasis);
appendFloatOptionalIfDefined(str, "flex", node->getStyle().flex);

View File

@ -43,7 +43,7 @@ YGStyle::YGStyle()
overflow(YGOverflowVisible),
display(YGDisplayFlex),
flex(YGFloatOptionalUndefined),
flexGrow(YGUndefined),
flexGrow(YGFloatOptionalUndefined),
flexShrink(YGUndefined),
flexBasis(kYGValueAuto),
margin(kYGDefaultEdgeValuesUnit),
@ -79,9 +79,11 @@ bool YGStyle::operator==(const YGStyle& style) {
areNonFloatValuesEqual && flex.value == style.flex.value;
}
if (!(YGFloatIsUndefined(flexGrow) && YGFloatIsUndefined(style.flexGrow))) {
areNonFloatValuesEqual = areNonFloatValuesEqual &&
flexGrow.isUndefined == style.flexGrow.isUndefined;
if (areNonFloatValuesEqual && !flexGrow.isUndefined) {
areNonFloatValuesEqual =
areNonFloatValuesEqual && flexGrow == style.flexGrow;
areNonFloatValuesEqual && flexGrow.value == style.flexGrow.value;
}
if (!(YGFloatIsUndefined(flexShrink) &&

View File

@ -21,7 +21,7 @@ struct YGStyle {
YGOverflow overflow;
YGDisplay display;
YGFloatOptional flex;
float flexGrow;
YGFloatOptional flexGrow;
float flexShrink;
YGValue flexBasis;
std::array<YGValue, YGEdgeCount> margin;

View File

@ -511,9 +511,9 @@ void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
}
float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
return YGFloatIsUndefined(node->getStyle().flexGrow)
return node->getStyle().flexGrow.isUndefined
? kDefaultFlexGrow
: node->getStyle().flexGrow;
: node->getStyle().flexGrow.value;
}
float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
@ -772,7 +772,21 @@ float YGNodeStyleGetFlex(const YGNodeRef node) {
: node->getStyle().flex.value;
}
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow);
// TODO(T26792433): Change the API to accept YGFloatOptional.
void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
if (!YGFloatOptionalFloatEquals(node->getStyle().flexGrow, flexGrow)) {
YGStyle style = node->getStyle();
if (YGFloatIsUndefined(flexGrow)) {
style.flexGrow = {true, 0};
} else {
style.flexGrow = {false, flexGrow};
}
node->setStyle(style);
node->markDirtyAndPropogate();
}
}
// YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow);
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink);
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, FlexBasis, flexBasis, flexBasis);