Skip to content

Commit 46817a3

Browse files
Antonio Corradofacebook-github-bot
authored andcommitted
Setting min=max dimension is treated as setting dimension
Summary: If a node has minDimension and maxDimension set at the same value, yoga will treat it as having a set dimension, doing less calculations. Reviewed By: emilsjolander Differential Revision: D4492395 fbshipit-source-id: 3f4293548399e006aa808b9586d24e77c7df1f21
1 parent 52f3471 commit 46817a3

File tree

4 files changed

+209
-93
lines changed

4 files changed

+209
-93
lines changed

java/jni/YGJNI.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ void jni_YGNodeRemoveChild(alias_ref<jobject>, jlong nativePointer, jlong childP
202202
YGNodeRemoveChild(_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer));
203203
}
204204

205-
void jni_YGNodeCalculateLayout(alias_ref<jobject>, jlong nativePointer, jfloat width, jfloat height) {
205+
void jni_YGNodeCalculateLayout(alias_ref<jobject>,
206+
jlong nativePointer,
207+
jfloat width,
208+
jfloat height) {
206209
const YGNodeRef root = _jlong2YGNodeRef(nativePointer);
207210
YGNodeCalculateLayout(root,
208211
static_cast<float>(width),

tests/YGMeasureTest.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,118 @@ TEST(YogaTest, measure_absolute_child_with_no_constraints) {
6767
YGNodeFreeRecursive(root);
6868
}
6969

70+
TEST(YogaTest, dont_measure_when_min_equals_max) {
71+
const YGNodeRef root = YGNodeNew();
72+
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
73+
YGNodeStyleSetWidth(root, 100);
74+
YGNodeStyleSetHeight(root, 100);
75+
76+
int measureCount = 0;
77+
78+
const YGNodeRef root_child0 = YGNodeNew();
79+
YGNodeSetContext(root_child0, &measureCount);
80+
YGNodeSetMeasureFunc(root_child0, _measure);
81+
YGNodeStyleSetMinWidth(root_child0, 10);
82+
YGNodeStyleSetMaxWidth(root_child0, 10);
83+
YGNodeStyleSetMinHeight(root_child0, 10);
84+
YGNodeStyleSetMaxHeight(root_child0, 10);
85+
YGNodeInsertChild(root, root_child0, 0);
86+
87+
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
88+
89+
ASSERT_EQ(0, measureCount);
90+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
91+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
92+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
93+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
94+
95+
YGNodeFreeRecursive(root);
96+
}
97+
98+
TEST(YogaTest, dont_measure_when_min_equals_max_percentages) {
99+
const YGNodeRef root = YGNodeNew();
100+
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
101+
YGNodeStyleSetWidth(root, 100);
102+
YGNodeStyleSetHeight(root, 100);
103+
104+
int measureCount = 0;
105+
106+
const YGNodeRef root_child0 = YGNodeNew();
107+
YGNodeSetContext(root_child0, &measureCount);
108+
YGNodeSetMeasureFunc(root_child0, _measure);
109+
YGNodeStyleSetMinWidthPercent(root_child0, 10);
110+
YGNodeStyleSetMaxWidthPercent(root_child0, 10);
111+
YGNodeStyleSetMinHeightPercent(root_child0, 10);
112+
YGNodeStyleSetMaxHeightPercent(root_child0, 10);
113+
YGNodeInsertChild(root, root_child0, 0);
114+
115+
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
116+
117+
ASSERT_EQ(0, measureCount);
118+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
119+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
120+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
121+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
122+
123+
YGNodeFreeRecursive(root);
124+
}
125+
126+
TEST(YogaTest, dont_measure_when_min_equals_max_mixed) {
127+
const YGNodeRef root = YGNodeNew();
128+
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
129+
YGNodeStyleSetWidth(root, 100);
130+
YGNodeStyleSetHeight(root, 100);
131+
132+
int measureCount = 0;
133+
134+
const YGNodeRef root_child0 = YGNodeNew();
135+
YGNodeSetContext(root_child0, &measureCount);
136+
YGNodeSetMeasureFunc(root_child0, _measure);
137+
YGNodeStyleSetMinWidthPercent(root_child0, 10);
138+
YGNodeStyleSetMaxWidthPercent(root_child0, 10);
139+
YGNodeStyleSetMinHeight(root_child0, 10);
140+
YGNodeStyleSetMaxHeight(root_child0, 10);
141+
YGNodeInsertChild(root, root_child0, 0);
142+
143+
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
144+
145+
ASSERT_EQ(0, measureCount);
146+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
147+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
148+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
149+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
150+
151+
YGNodeFreeRecursive(root);
152+
}
153+
154+
TEST(YogaTest, dont_measure_when_min_equals_max_mixed_2) {
155+
const YGNodeRef root = YGNodeNew();
156+
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
157+
YGNodeStyleSetWidth(root, 100);
158+
YGNodeStyleSetHeight(root, 100);
159+
160+
int measureCount = 0;
161+
162+
const YGNodeRef root_child0 = YGNodeNew();
163+
YGNodeSetContext(root_child0, &measureCount);
164+
YGNodeSetMeasureFunc(root_child0, _measure);
165+
YGNodeStyleSetMinWidth(root_child0, 10);
166+
YGNodeStyleSetMaxWidth(root_child0, 10);
167+
YGNodeStyleSetMinHeightPercent(root_child0, 10);
168+
YGNodeStyleSetMaxHeightPercent(root_child0, 10);
169+
YGNodeInsertChild(root, root_child0, 0);
170+
171+
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
172+
173+
ASSERT_EQ(0, measureCount);
174+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
175+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
176+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
177+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
178+
179+
YGNodeFreeRecursive(root);
180+
}
181+
70182
#if GTEST_HAS_DEATH_TEST
71183
TEST(YogaTest, cannot_add_child_to_node_with_measure_func) {
72184
const YGNodeRef root = YGNodeNew();

yoga/YGEnums.h

Lines changed: 45 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,21 @@ YG_EXTERN_C_BEGIN
1515

1616
#define YGAlignCount 6
1717
typedef YG_ENUM_BEGIN(YGAlign) {
18-
YGAlignAuto,
19-
YGAlignFlexStart,
20-
YGAlignCenter,
21-
YGAlignFlexEnd,
22-
YGAlignStretch,
23-
YGAlignBaseline,
24-
} YG_ENUM_END(YGAlign);
18+
YGAlignAuto, YGAlignFlexStart, YGAlignCenter, YGAlignFlexEnd, YGAlignStretch, YGAlignBaseline,
19+
}
20+
YG_ENUM_END(YGAlign);
2521

2622
#define YGDimensionCount 2
2723
typedef YG_ENUM_BEGIN(YGDimension) {
28-
YGDimensionWidth,
29-
YGDimensionHeight,
30-
} YG_ENUM_END(YGDimension);
24+
YGDimensionWidth, YGDimensionHeight,
25+
}
26+
YG_ENUM_END(YGDimension);
3127

3228
#define YGDirectionCount 3
3329
typedef YG_ENUM_BEGIN(YGDirection) {
34-
YGDirectionInherit,
35-
YGDirectionLTR,
36-
YGDirectionRTL,
37-
} YG_ENUM_END(YGDirection);
30+
YGDirectionInherit, YGDirectionLTR, YGDirectionRTL,
31+
}
32+
YG_ENUM_END(YGDirection);
3833

3934
#define YGDisplayCount 2
4035
typedef YG_ENUM_BEGIN(YGDisplay) {
@@ -44,87 +39,71 @@ typedef YG_ENUM_BEGIN(YGDisplay) {
4439

4540
#define YGEdgeCount 9
4641
typedef YG_ENUM_BEGIN(YGEdge) {
47-
YGEdgeLeft,
48-
YGEdgeTop,
49-
YGEdgeRight,
50-
YGEdgeBottom,
51-
YGEdgeStart,
52-
YGEdgeEnd,
53-
YGEdgeHorizontal,
54-
YGEdgeVertical,
55-
YGEdgeAll,
56-
} YG_ENUM_END(YGEdge);
42+
YGEdgeLeft, YGEdgeTop, YGEdgeRight, YGEdgeBottom, YGEdgeStart, YGEdgeEnd, YGEdgeHorizontal,
43+
YGEdgeVertical, YGEdgeAll,
44+
}
45+
YG_ENUM_END(YGEdge);
5746

5847
#define YGExperimentalFeatureCount 2
5948
typedef YG_ENUM_BEGIN(YGExperimentalFeature) {
60-
YGExperimentalFeatureRounding,
61-
YGExperimentalFeatureWebFlexBasis,
62-
} YG_ENUM_END(YGExperimentalFeature);
49+
YGExperimentalFeatureRounding, YGExperimentalFeatureWebFlexBasis,
50+
}
51+
YG_ENUM_END(YGExperimentalFeature);
6352

6453
#define YGFlexDirectionCount 4
6554
typedef YG_ENUM_BEGIN(YGFlexDirection) {
66-
YGFlexDirectionColumn,
67-
YGFlexDirectionColumnReverse,
68-
YGFlexDirectionRow,
69-
YGFlexDirectionRowReverse,
70-
} YG_ENUM_END(YGFlexDirection);
55+
YGFlexDirectionColumn, YGFlexDirectionColumnReverse, YGFlexDirectionRow,
56+
YGFlexDirectionRowReverse,
57+
}
58+
YG_ENUM_END(YGFlexDirection);
7159

7260
#define YGJustifyCount 5
7361
typedef YG_ENUM_BEGIN(YGJustify) {
74-
YGJustifyFlexStart,
75-
YGJustifyCenter,
76-
YGJustifyFlexEnd,
77-
YGJustifySpaceBetween,
78-
YGJustifySpaceAround,
79-
} YG_ENUM_END(YGJustify);
62+
YGJustifyFlexStart, YGJustifyCenter, YGJustifyFlexEnd, YGJustifySpaceBetween,
63+
YGJustifySpaceAround,
64+
}
65+
YG_ENUM_END(YGJustify);
8066

8167
#define YGLogLevelCount 5
8268
typedef YG_ENUM_BEGIN(YGLogLevel) {
83-
YGLogLevelError,
84-
YGLogLevelWarn,
85-
YGLogLevelInfo,
86-
YGLogLevelDebug,
87-
YGLogLevelVerbose,
88-
} YG_ENUM_END(YGLogLevel);
69+
YGLogLevelError, YGLogLevelWarn, YGLogLevelInfo, YGLogLevelDebug, YGLogLevelVerbose,
70+
}
71+
YG_ENUM_END(YGLogLevel);
8972

9073
#define YGMeasureModeCount 3
9174
typedef YG_ENUM_BEGIN(YGMeasureMode) {
92-
YGMeasureModeUndefined,
93-
YGMeasureModeExactly,
94-
YGMeasureModeAtMost,
95-
} YG_ENUM_END(YGMeasureMode);
75+
YGMeasureModeUndefined, YGMeasureModeExactly, YGMeasureModeAtMost,
76+
}
77+
YG_ENUM_END(YGMeasureMode);
9678

9779
#define YGOverflowCount 3
9880
typedef YG_ENUM_BEGIN(YGOverflow) {
99-
YGOverflowVisible,
100-
YGOverflowHidden,
101-
YGOverflowScroll,
102-
} YG_ENUM_END(YGOverflow);
81+
YGOverflowVisible, YGOverflowHidden, YGOverflowScroll,
82+
}
83+
YG_ENUM_END(YGOverflow);
10384

10485
#define YGPositionTypeCount 2
10586
typedef YG_ENUM_BEGIN(YGPositionType) {
106-
YGPositionTypeRelative,
107-
YGPositionTypeAbsolute,
108-
} YG_ENUM_END(YGPositionType);
87+
YGPositionTypeRelative, YGPositionTypeAbsolute,
88+
}
89+
YG_ENUM_END(YGPositionType);
10990

11091
#define YGPrintOptionsCount 3
11192
typedef YG_ENUM_BEGIN(YGPrintOptions) {
112-
YGPrintOptionsLayout = 1,
113-
YGPrintOptionsStyle = 2,
114-
YGPrintOptionsChildren = 4,
115-
} YG_ENUM_END(YGPrintOptions);
93+
YGPrintOptionsLayout = 1, YGPrintOptionsStyle = 2, YGPrintOptionsChildren = 4,
94+
}
95+
YG_ENUM_END(YGPrintOptions);
11696

11797
#define YGUnitCount 3
11898
typedef YG_ENUM_BEGIN(YGUnit) {
119-
YGUnitUndefined,
120-
YGUnitPixel,
121-
YGUnitPercent,
122-
} YG_ENUM_END(YGUnit);
99+
YGUnitUndefined, YGUnitPixel, YGUnitPercent,
100+
}
101+
YG_ENUM_END(YGUnit);
123102

124103
#define YGWrapCount 2
125104
typedef YG_ENUM_BEGIN(YGWrap) {
126-
YGWrapNoWrap,
127-
YGWrapWrap,
128-
} YG_ENUM_END(YGWrap);
105+
YGWrapNoWrap, YGWrapWrap,
106+
}
107+
YG_ENUM_END(YGWrap);
129108

130109
YG_EXTERN_C_END

0 commit comments

Comments
 (0)