Skip to content

Commit c9bbcdb

Browse files
woehrl01bowerman0
authored andcommitted
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 facebook#630 Closes facebook/yoga#648 Differential Revision: D6408013 Pulled By: emilsjolander fbshipit-source-id: dc2a848d84d3de9f4650fac9e41d7c8169446406
1 parent 33becbd commit c9bbcdb

File tree

1 file changed

+115
-84
lines changed

1 file changed

+115
-84
lines changed

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 115 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -534,50 +534,68 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) {
534534
} \
535535
}
536536

537-
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL(type, name, paramName, instanceName) \
538-
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
539-
if (node->style.instanceName.value != paramName || \
540-
node->style.instanceName.unit != YGUnitPoint) { \
541-
node->style.instanceName.value = paramName; \
542-
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPoint; \
543-
YGNodeMarkDirtyInternal(node); \
544-
} \
545-
} \
546-
\
547-
void YGNodeStyleSet##name##Percent(const YGNodeRef node, const type paramName) { \
548-
if (node->style.instanceName.value != paramName || \
549-
node->style.instanceName.unit != YGUnitPercent) { \
550-
node->style.instanceName.value = paramName; \
551-
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
552-
YGNodeMarkDirtyInternal(node); \
553-
} \
554-
}
555-
556-
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL(type, name, paramName, instanceName) \
557-
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
558-
if (node->style.instanceName.value != paramName || \
559-
node->style.instanceName.unit != YGUnitPoint) { \
560-
node->style.instanceName.value = paramName; \
561-
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPoint; \
562-
YGNodeMarkDirtyInternal(node); \
563-
} \
564-
} \
565-
\
566-
void YGNodeStyleSet##name##Percent(const YGNodeRef node, const type paramName) { \
567-
if (node->style.instanceName.value != paramName || \
568-
node->style.instanceName.unit != YGUnitPercent) { \
569-
node->style.instanceName.value = paramName; \
570-
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
571-
YGNodeMarkDirtyInternal(node); \
572-
} \
573-
} \
574-
\
575-
void YGNodeStyleSet##name##Auto(const YGNodeRef node) { \
576-
if (node->style.instanceName.unit != YGUnitAuto) { \
577-
node->style.instanceName.value = YGUndefined; \
578-
node->style.instanceName.unit = YGUnitAuto; \
579-
YGNodeMarkDirtyInternal(node); \
580-
} \
537+
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
538+
type, name, paramName, instanceName) \
539+
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
540+
YGValue value = { \
541+
.value = paramName, \
542+
.unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
543+
}; \
544+
if ((node->style.instanceName.value != value.value && \
545+
value.unit != YGUnitUndefined) || \
546+
node->style.instanceName.unit != value.unit) { \
547+
node->style.instanceName = value; \
548+
YGNodeMarkDirtyInternal(node); \
549+
} \
550+
} \
551+
\
552+
void YGNodeStyleSet##name##Percent( \
553+
const YGNodeRef node, const type paramName) { \
554+
YGValue value = { \
555+
.value = paramName, \
556+
.unit = \
557+
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
558+
}; \
559+
if ((node->style.instanceName.value != value.value && \
560+
value.unit != YGUnitUndefined) || \
561+
node->style.instanceName.unit != value.unit) { \
562+
node->style.instanceName = value; \
563+
YGNodeMarkDirtyInternal(node); \
564+
} \
565+
}
566+
567+
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL( \
568+
type, name, paramName, instanceName) \
569+
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
570+
YGValue value = { \
571+
.value = paramName, \
572+
.unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
573+
}; \
574+
if ((node->style.instanceName.value != value.value && \
575+
value.unit != YGUnitUndefined) || \
576+
node->style.instanceName.unit != value.unit) { \
577+
node->style.instanceName = value; \
578+
YGNodeMarkDirtyInternal(node); \
579+
} \
580+
} \
581+
\
582+
void YGNodeStyleSet##name##Percent( \
583+
const YGNodeRef node, const type paramName) { \
584+
if (node->style.instanceName.value != paramName || \
585+
node->style.instanceName.unit != YGUnitPercent) { \
586+
node->style.instanceName.value = paramName; \
587+
node->style.instanceName.unit = \
588+
YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
589+
YGNodeMarkDirtyInternal(node); \
590+
} \
591+
} \
592+
\
593+
void YGNodeStyleSet##name##Auto(const YGNodeRef node) { \
594+
if (node->style.instanceName.unit != YGUnitAuto) { \
595+
node->style.instanceName.value = YGUndefined; \
596+
node->style.instanceName.unit = YGUnitAuto; \
597+
YGNodeMarkDirtyInternal(node); \
598+
} \
581599
}
582600

583601
#define YG_NODE_STYLE_PROPERTY_IMPL(type, name, paramName, instanceName) \
@@ -610,46 +628,59 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) {
610628
} \
611629
}
612630

613-
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \
614-
void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \
615-
if (node->style.instanceName[edge].value != paramName || \
616-
node->style.instanceName[edge].unit != YGUnitPoint) { \
617-
node->style.instanceName[edge].value = paramName; \
618-
node->style.instanceName[edge].unit = \
619-
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \
620-
YGNodeMarkDirtyInternal(node); \
621-
} \
622-
} \
623-
\
624-
void YGNodeStyleSet##name##Percent(const YGNodeRef node, \
625-
const YGEdge edge, \
626-
const float paramName) { \
627-
if (node->style.instanceName[edge].value != paramName || \
628-
node->style.instanceName[edge].unit != YGUnitPercent) { \
629-
node->style.instanceName[edge].value = paramName; \
630-
node->style.instanceName[edge].unit = \
631-
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent; \
632-
YGNodeMarkDirtyInternal(node); \
633-
} \
634-
} \
635-
\
636-
WIN_STRUCT(type) YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
637-
return WIN_STRUCT_REF(node->style.instanceName[edge]); \
638-
}
639-
640-
#define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \
641-
void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \
642-
if (node->style.instanceName[edge].value != paramName || \
643-
node->style.instanceName[edge].unit != YGUnitPoint) { \
644-
node->style.instanceName[edge].value = paramName; \
645-
node->style.instanceName[edge].unit = \
646-
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \
647-
YGNodeMarkDirtyInternal(node); \
648-
} \
649-
} \
650-
\
651-
float YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
652-
return node->style.instanceName[edge].value; \
631+
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL( \
632+
type, name, paramName, instanceName) \
633+
void YGNodeStyleSet##name( \
634+
const YGNodeRef node, const YGEdge edge, const float paramName) { \
635+
YGValue value = { \
636+
.value = paramName, \
637+
.unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
638+
}; \
639+
if ((node->style.instanceName[edge].value != value.value && \
640+
value.unit != YGUnitUndefined) || \
641+
node->style.instanceName[edge].unit != value.unit) { \
642+
node->style.instanceName[edge] = value; \
643+
YGNodeMarkDirtyInternal(node); \
644+
} \
645+
} \
646+
\
647+
void YGNodeStyleSet##name##Percent( \
648+
const YGNodeRef node, const YGEdge edge, const float paramName) { \
649+
YGValue value = { \
650+
.value = paramName, \
651+
.unit = \
652+
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
653+
}; \
654+
if ((node->style.instanceName[edge].value != value.value && \
655+
value.unit != YGUnitUndefined) || \
656+
node->style.instanceName[edge].unit != value.unit) { \
657+
node->style.instanceName[edge] = value; \
658+
YGNodeMarkDirtyInternal(node); \
659+
} \
660+
} \
661+
\
662+
WIN_STRUCT(type) \
663+
YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
664+
return WIN_STRUCT_REF(node->style.instanceName[edge]); \
665+
}
666+
667+
#define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \
668+
void YGNodeStyleSet##name( \
669+
const YGNodeRef node, const YGEdge edge, const float paramName) { \
670+
YGValue value = { \
671+
.value = paramName, \
672+
.unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
673+
}; \
674+
if ((node->style.instanceName[edge].value != value.value && \
675+
value.unit != YGUnitUndefined) || \
676+
node->style.instanceName[edge].unit != value.unit) { \
677+
node->style.instanceName[edge] = value; \
678+
YGNodeMarkDirtyInternal(node); \
679+
} \
680+
} \
681+
\
682+
float YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
683+
return node->style.instanceName[edge].value; \
653684
}
654685

655686
#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \

0 commit comments

Comments
 (0)