Do not mark node as dirty if, new and old values are undefined

Summary:
If we have a values already set to undefined and set it to undefined again, we invalidate the layout. This change takes this case into account and keeps the layout valid.
Fixes #630
Closes https://github.com/facebook/yoga/pull/648

Differential Revision: D6408013

Pulled By: emilsjolander

fbshipit-source-id: dc2a848d84d3de9f4650fac9e41d7c8169446406
This commit is contained in:
Lukas Wöhrl 2017-11-27 03:06:15 -08:00 committed by Facebook Github Bot
parent a383b8ca05
commit 41da6e3128

View File

@ -534,40 +534,58 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) {
} \ } \
} }
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL(type, name, paramName, instanceName) \ #define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
type, name, paramName, instanceName) \
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
if (node->style.instanceName.value != paramName || \ YGValue value = { \
node->style.instanceName.unit != YGUnitPoint) { \ .value = paramName, \
node->style.instanceName.value = paramName; \ .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPoint; \ }; \
if ((node->style.instanceName.value != value.value && \
value.unit != YGUnitUndefined) || \
node->style.instanceName.unit != value.unit) { \
node->style.instanceName = value; \
YGNodeMarkDirtyInternal(node); \ YGNodeMarkDirtyInternal(node); \
} \ } \
} \ } \
\ \
void YGNodeStyleSet##name##Percent(const YGNodeRef node, const type paramName) { \ void YGNodeStyleSet##name##Percent( \
if (node->style.instanceName.value != paramName || \ const YGNodeRef node, const type paramName) { \
node->style.instanceName.unit != YGUnitPercent) { \ YGValue value = { \
node->style.instanceName.value = paramName; \ .value = paramName, \
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \ .unit = \
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
}; \
if ((node->style.instanceName.value != value.value && \
value.unit != YGUnitUndefined) || \
node->style.instanceName.unit != value.unit) { \
node->style.instanceName = value; \
YGNodeMarkDirtyInternal(node); \ YGNodeMarkDirtyInternal(node); \
} \ } \
} }
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL(type, name, paramName, instanceName) \ #define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL( \
type, name, paramName, instanceName) \
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
if (node->style.instanceName.value != paramName || \ YGValue value = { \
node->style.instanceName.unit != YGUnitPoint) { \ .value = paramName, \
node->style.instanceName.value = paramName; \ .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPoint; \ }; \
if ((node->style.instanceName.value != value.value && \
value.unit != YGUnitUndefined) || \
node->style.instanceName.unit != value.unit) { \
node->style.instanceName = value; \
YGNodeMarkDirtyInternal(node); \ YGNodeMarkDirtyInternal(node); \
} \ } \
} \ } \
\ \
void YGNodeStyleSet##name##Percent(const YGNodeRef node, const type paramName) { \ void YGNodeStyleSet##name##Percent( \
const YGNodeRef node, const type paramName) { \
if (node->style.instanceName.value != paramName || \ if (node->style.instanceName.value != paramName || \
node->style.instanceName.unit != YGUnitPercent) { \ node->style.instanceName.unit != YGUnitPercent) { \
node->style.instanceName.value = paramName; \ node->style.instanceName.value = paramName; \
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \ node->style.instanceName.unit = \
YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
YGNodeMarkDirtyInternal(node); \ YGNodeMarkDirtyInternal(node); \
} \ } \
} \ } \
@ -610,40 +628,53 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) {
} \ } \
} }
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \ #define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL( \
void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \ type, name, paramName, instanceName) \
if (node->style.instanceName[edge].value != paramName || \ void YGNodeStyleSet##name( \
node->style.instanceName[edge].unit != YGUnitPoint) { \ const YGNodeRef node, const YGEdge edge, const float paramName) { \
node->style.instanceName[edge].value = paramName; \ YGValue value = { \
node->style.instanceName[edge].unit = \ .value = paramName, \
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \ .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
}; \
if ((node->style.instanceName[edge].value != value.value && \
value.unit != YGUnitUndefined) || \
node->style.instanceName[edge].unit != value.unit) { \
node->style.instanceName[edge] = value; \
YGNodeMarkDirtyInternal(node); \ YGNodeMarkDirtyInternal(node); \
} \ } \
} \ } \
\ \
void YGNodeStyleSet##name##Percent(const YGNodeRef node, \ void YGNodeStyleSet##name##Percent( \
const YGEdge edge, \ const YGNodeRef node, const YGEdge edge, const float paramName) { \
const float paramName) { \ YGValue value = { \
if (node->style.instanceName[edge].value != paramName || \ .value = paramName, \
node->style.instanceName[edge].unit != YGUnitPercent) { \ .unit = \
node->style.instanceName[edge].value = paramName; \ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
node->style.instanceName[edge].unit = \ }; \
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent; \ if ((node->style.instanceName[edge].value != value.value && \
value.unit != YGUnitUndefined) || \
node->style.instanceName[edge].unit != value.unit) { \
node->style.instanceName[edge] = value; \
YGNodeMarkDirtyInternal(node); \ YGNodeMarkDirtyInternal(node); \
} \ } \
} \ } \
\ \
WIN_STRUCT(type) YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \ WIN_STRUCT(type) \
YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
return WIN_STRUCT_REF(node->style.instanceName[edge]); \ return WIN_STRUCT_REF(node->style.instanceName[edge]); \
} }
#define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \ #define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \
void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \ void YGNodeStyleSet##name( \
if (node->style.instanceName[edge].value != paramName || \ const YGNodeRef node, const YGEdge edge, const float paramName) { \
node->style.instanceName[edge].unit != YGUnitPoint) { \ YGValue value = { \
node->style.instanceName[edge].value = paramName; \ .value = paramName, \
node->style.instanceName[edge].unit = \ .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \ }; \
if ((node->style.instanceName[edge].value != value.value && \
value.unit != YGUnitUndefined) || \
node->style.instanceName[edge].unit != value.unit) { \
node->style.instanceName[edge] = value; \
YGNodeMarkDirtyInternal(node); \ YGNodeMarkDirtyInternal(node); \
} \ } \
} \ } \