Change the type of flexShrink to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7232171

fbshipit-source-id: 3111119d3d74a7035c01132bff61b30cf44e120a
This commit is contained in:
Pritesh Nandgaonkar 2018-03-14 04:17:16 -07:00 committed by Facebook Github Bot
parent 3274e9fa51
commit e3af1508c8
5 changed files with 26 additions and 20 deletions

View File

@ -605,8 +605,8 @@ float YGNode::resolveFlexShrink() {
if (parent_ == nullptr) {
return 0.0;
}
if (!YGFloatIsUndefined(style_.flexShrink)) {
return style_.flexShrink;
if (!style_.flexShrink.isUndefined) {
return style_.flexShrink.value;
}
if (!config_->useWebDefaults && !style_.flex.isUndefined &&
style_.flex.value < 0.0f) {

View File

@ -48,13 +48,6 @@ static void appendFloatOptionalIfDefined(
}
}
static void
appendFloatIfNotUndefined(string* base, const string key, const float num) {
if (!YGFloatIsUndefined(num)) {
appendFormatedString(base, "%s: %g; ", key.c_str(), num);
}
}
static void appendNumberIfNotUndefined(
string* base,
const string key,
@ -162,7 +155,8 @@ void YGNodeToString(
str, "align-self: %s; ", YGAlignToString(node->getStyle().alignSelf));
}
appendFloatOptionalIfDefined(str, "flex-grow", node->getStyle().flexGrow);
appendFloatIfNotUndefined(str, "flex-shrink", node->getStyle().flexShrink);
appendFloatOptionalIfDefined(
str, "flex-shrink", node->getStyle().flexShrink);
appendNumberIfNotAuto(str, "flex-basis", node->getStyle().flexBasis);
appendFloatOptionalIfDefined(str, "flex", node->getStyle().flex);

View File

@ -44,7 +44,7 @@ YGStyle::YGStyle()
display(YGDisplayFlex),
flex(YGFloatOptionalUndefined),
flexGrow(YGFloatOptionalUndefined),
flexShrink(YGUndefined),
flexShrink(YGFloatOptionalUndefined),
flexBasis(kYGValueAuto),
margin(kYGDefaultEdgeValuesUnit),
position(kYGDefaultEdgeValuesUnit),
@ -86,10 +86,11 @@ bool YGStyle::operator==(const YGStyle& style) {
areNonFloatValuesEqual && flexGrow.value == style.flexGrow.value;
}
if (!(YGFloatIsUndefined(flexShrink) &&
YGFloatIsUndefined(style.flexShrink))) {
areNonFloatValuesEqual = areNonFloatValuesEqual &&
flexShrink.isUndefined == style.flexShrink.isUndefined;
if (areNonFloatValuesEqual && !style.flexShrink.isUndefined) {
areNonFloatValuesEqual =
areNonFloatValuesEqual && flexShrink == style.flexShrink;
areNonFloatValuesEqual && flexShrink.value == style.flexShrink.value;
}
if (!(YGFloatIsUndefined(aspectRatio) &&

View File

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

View File

@ -517,10 +517,10 @@ float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
}
float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
return YGFloatIsUndefined(node->getStyle().flexShrink)
return node->getStyle().flexShrink.isUndefined
? (node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink
: kDefaultFlexShrink)
: node->getStyle().flexShrink;
: node->getStyle().flexShrink.value;
}
#define YG_NODE_STYLE_PROPERTY_SETTER_IMPL( \
@ -786,10 +786,21 @@ void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
}
}
// 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);
// TODO(T26792433): Change the API to accept YGFloatOptional.
void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) {
if (!YGFloatOptionalFloatEquals(node->getStyle().flexShrink, flexShrink)) {
YGStyle style = node->getStyle();
if (YGFloatIsUndefined(flexShrink)) {
style.flexGrow = {true, 0};
} else {
style.flexShrink = {false, flexShrink};
}
node->setStyle(style);
node->markDirtyAndPropogate();
}
}
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, FlexBasis, flexBasis, flexBasis);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Position, position, position);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Margin, margin, margin);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Margin, margin);