From ea8b7e0c918cab7e976bd05ef2390c5dec33d410 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Thu, 16 Feb 2017 06:47:28 -0800 Subject: [PATCH] Fix up some small issues with YGUnitAuto Summary: There are still some pieces of RN which does not handle YGUnitAuto and makes use of either the value being nan or the unit being undefined. This diff makes this more robust to those kinds of situations. Reviewed By: wwjholmes Differential Revision: D4567045 fbshipit-source-id: ace5fd89bd534a6bb5ec7dba0c3afbf13d62d7c9 --- yoga/Yoga.c | 10 +++++----- yoga/Yoga.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/yoga/Yoga.c b/yoga/Yoga.c index ccb947d5..9d3a37c8 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -434,7 +434,7 @@ inline float YGNodeStyleGetFlexShrink(const YGNodeRef node) { } static inline const YGValue *YGNodeStyleGetFlexBasisPtr(const YGNodeRef node) { - if (node->style.flexBasis.unit != YGUnitAuto) { + if (node->style.flexBasis.unit != YGUnitAuto && node->style.flexBasis.unit != YGUnitUndefined) { return &node->style.flexBasis; } if (!YGFloatIsUndefined(node->style.flex) && node->style.flex > 0.0f) { @@ -477,7 +477,7 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { node->style.instanceName.unit != YGUnitPoint) { \ node->style.instanceName.value = paramName; \ node->style.instanceName.unit = \ - YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \ + YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPoint; \ YGNodeMarkDirtyInternal(node); \ } \ } \ @@ -487,7 +487,7 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { node->style.instanceName.unit != YGUnitPercent) { \ node->style.instanceName.value = paramName; \ node->style.instanceName.unit = \ - YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent; \ + YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \ YGNodeMarkDirtyInternal(node); \ } \ } @@ -496,7 +496,7 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ if (node->style.instanceName.value != paramName || \ node->style.instanceName.unit != YGUnitPoint) { \ - node->style.instanceName.value = YGFloatIsUndefined(paramName) ? YGUndefined : paramName; \ + node->style.instanceName.value = paramName; \ node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPoint; \ YGNodeMarkDirtyInternal(node); \ } \ @@ -505,7 +505,7 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { void YGNodeStyleSet##name##Percent(const YGNodeRef node, const type paramName) { \ if (node->style.instanceName.value != paramName || \ node->style.instanceName.unit != YGUnitPercent) { \ - node->style.instanceName.value = YGFloatIsUndefined(paramName) ? YGUndefined : paramName; \ + node->style.instanceName.value = paramName; \ node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \ YGNodeMarkDirtyInternal(node); \ } \ diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 4969f17c..4174e786 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -44,7 +44,7 @@ typedef struct YGValue { } YGValue; static const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined}; -static const YGValue YGValueAuto = {0, YGUnitAuto}; +static const YGValue YGValueAuto = {YGUndefined, YGUnitAuto}; typedef struct YGNode *YGNodeRef; typedef YGSize (*YGMeasureFunc)(YGNodeRef node,