Skip to content

Commit 1fe9e15

Browse files
joevilchesfacebook-github-bot
authored andcommitted
Update public API for intrinsic sizing setters (#46939)
Summary: X-link: facebook/yoga#1722 tsia! opted for one function for each keyword just like auto. This is kinda annoying and not the most sustainable, so maybe it makes more sense to make a new enum here and just add one function Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D64002837
1 parent dbf5944 commit 1fe9e15

File tree

8 files changed

+450
-18
lines changed

8 files changed

+450
-18
lines changed

packages/react-native/React/Views/RCTShadowView.m

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ + (YGConfigRef)yogaConfig
6363
#define RCT_SET_YGVALUE(ygvalue, setter, ...) \
6464
switch (ygvalue.unit) { \
6565
case YGUnitAuto: \
66+
case YGUnitMaxContent: \
67+
case YGUnitFitContent: \
68+
case YGUnitStretch: \
6669
case YGUnitUndefined: \
6770
setter(__VA_ARGS__, YGUndefined); \
6871
break; \
@@ -88,6 +91,35 @@ + (YGConfigRef)yogaConfig
8891
case YGUnitPercent: \
8992
setter##Percent(__VA_ARGS__, ygvalue.value); \
9093
break; \
94+
case YGUnitMaxContent: \
95+
case YGUnitFitContent: \
96+
case YGUnitStretch: \
97+
break; \
98+
}
99+
100+
#define RCT_SET_YGVALUE_AUTO_INTRINSIC(ygvalue, setter, ...) \
101+
switch (ygvalue.unit) { \
102+
case YGUnitAuto: \
103+
setter##Auto(__VA_ARGS__); \
104+
break; \
105+
case YGUnitMaxContent: \
106+
setter##MaxContent(__VA_ARGS__); \
107+
break; \
108+
case YGUnitFitContent: \
109+
setter##FitContent(__VA_ARGS__); \
110+
break; \
111+
case YGUnitStretch: \
112+
setter##Stretch(__VA_ARGS__); \
113+
break; \
114+
case YGUnitUndefined: \
115+
setter(__VA_ARGS__, YGUndefined); \
116+
break; \
117+
case YGUnitPoint: \
118+
setter(__VA_ARGS__, ygvalue.value); \
119+
break; \
120+
case YGUnitPercent: \
121+
setter##Percent(__VA_ARGS__, ygvalue.value); \
122+
break; \
91123
}
92124

93125
static void RCTProcessMetaPropsPadding(const YGValue metaProps[META_PROP_COUNT], YGNodeRef node)
@@ -483,14 +515,14 @@ -(float)border##prop##Width \
483515
RCT_BORDER_PROPERTY(End, END)
484516

485517
// Dimensions
486-
#define RCT_DIMENSION_PROPERTY(setProp, getProp, cssProp) \
487-
-(void)set##setProp : (YGValue)value \
488-
{ \
489-
RCT_SET_YGVALUE_AUTO(value, YGNodeStyleSet##cssProp, _yogaNode); \
490-
} \
491-
-(YGValue)getProp \
492-
{ \
493-
return YGNodeStyleGet##cssProp(_yogaNode); \
518+
#define RCT_DIMENSION_PROPERTY(setProp, getProp, cssProp) \
519+
-(void)set##setProp : (YGValue)value \
520+
{ \
521+
RCT_SET_YGVALUE_AUTO_INTRINSIC(value, YGNodeStyleSet##cssProp, _yogaNode); \
522+
} \
523+
-(YGValue)getProp \
524+
{ \
525+
return YGNodeStyleGet##cssProp(_yogaNode); \
494526
}
495527

496528
#define RCT_MIN_MAX_DIMENSION_PROPERTY(setProp, getProp, cssProp) \
@@ -634,7 +666,7 @@ - (void)setLocalData:(__unused NSObject *)localData
634666

635667
- (void)setFlexBasis:(YGValue)value
636668
{
637-
RCT_SET_YGVALUE_AUTO(value, YGNodeStyleSetFlexBasis, _yogaNode);
669+
RCT_SET_YGVALUE_AUTO_INTRINSIC(value, YGNodeStyleSetFlexBasis, _yogaNode);
638670
}
639671

640672
- (YGValue)flexBasis

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNative.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public class YogaNative {
7474
static native void jni_YGNodeStyleSetFlexBasisJNI(long nativePointer, float flexBasis);
7575
static native void jni_YGNodeStyleSetFlexBasisPercentJNI(long nativePointer, float percent);
7676
static native void jni_YGNodeStyleSetFlexBasisAutoJNI(long nativePointer);
77+
static native void jni_YGNodeStyleSetFlexBasisMaxContentJNI(long nativePointer);
78+
static native void jni_YGNodeStyleSetFlexBasisFitContentJNI(long nativePointer);
79+
static native void jni_YGNodeStyleSetFlexBasisStretchJNI(long nativePointer);
7780
static native long jni_YGNodeStyleGetMarginJNI(long nativePointer, int edge);
7881
static native void jni_YGNodeStyleSetMarginJNI(long nativePointer, int edge, float margin);
7982
static native void jni_YGNodeStyleSetMarginPercentJNI(long nativePointer, int edge, float percent);
@@ -91,22 +94,40 @@ public class YogaNative {
9194
static native void jni_YGNodeStyleSetWidthJNI(long nativePointer, float width);
9295
static native void jni_YGNodeStyleSetWidthPercentJNI(long nativePointer, float percent);
9396
static native void jni_YGNodeStyleSetWidthAutoJNI(long nativePointer);
97+
static native void jni_YGNodeStyleSetWidthMaxContentJNI(long nativePointer);
98+
static native void jni_YGNodeStyleSetWidthFitContentJNI(long nativePointer);
99+
static native void jni_YGNodeStyleSetWidthStretchJNI(long nativePointer);
94100
static native long jni_YGNodeStyleGetHeightJNI(long nativePointer);
95101
static native void jni_YGNodeStyleSetHeightJNI(long nativePointer, float height);
96102
static native void jni_YGNodeStyleSetHeightPercentJNI(long nativePointer, float percent);
97103
static native void jni_YGNodeStyleSetHeightAutoJNI(long nativePointer);
104+
static native void jni_YGNodeStyleSetHeightMaxContentJNI(long nativePointer);
105+
static native void jni_YGNodeStyleSetHeightFitContentJNI(long nativePointer);
106+
static native void jni_YGNodeStyleSetHeightStretchJNI(long nativePointer);
98107
static native long jni_YGNodeStyleGetMinWidthJNI(long nativePointer);
99108
static native void jni_YGNodeStyleSetMinWidthJNI(long nativePointer, float minWidth);
100109
static native void jni_YGNodeStyleSetMinWidthPercentJNI(long nativePointer, float percent);
110+
static native void jni_YGNodeStyleSetMinWidthMaxContentJNI(long nativePointer);
111+
static native void jni_YGNodeStyleSetMinWidthFitContentJNI(long nativePointer);
112+
static native void jni_YGNodeStyleSetMinWidthStretchJNI(long nativePointer);
101113
static native long jni_YGNodeStyleGetMinHeightJNI(long nativePointer);
102114
static native void jni_YGNodeStyleSetMinHeightJNI(long nativePointer, float minHeight);
103115
static native void jni_YGNodeStyleSetMinHeightPercentJNI(long nativePointer, float percent);
116+
static native void jni_YGNodeStyleSetMinHeightMaxContentJNI(long nativePointer);
117+
static native void jni_YGNodeStyleSetMinHeightFitContentJNI(long nativePointer);
118+
static native void jni_YGNodeStyleSetMinHeightStretchJNI(long nativePointer);
104119
static native long jni_YGNodeStyleGetMaxWidthJNI(long nativePointer);
105120
static native void jni_YGNodeStyleSetMaxWidthJNI(long nativePointer, float maxWidth);
106121
static native void jni_YGNodeStyleSetMaxWidthPercentJNI(long nativePointer, float percent);
122+
static native void jni_YGNodeStyleSetMaxWidthMaxContentJNI(long nativePointer);
123+
static native void jni_YGNodeStyleSetMaxWidthFitContentJNI(long nativePointer);
124+
static native void jni_YGNodeStyleSetMaxWidthStretchJNI(long nativePointer);
107125
static native long jni_YGNodeStyleGetMaxHeightJNI(long nativePointer);
108126
static native void jni_YGNodeStyleSetMaxHeightJNI(long nativePointer, float maxheight);
109127
static native void jni_YGNodeStyleSetMaxHeightPercentJNI(long nativePointer, float percent);
128+
static native void jni_YGNodeStyleSetMaxHeightMaxContentJNI(long nativePointer);
129+
static native void jni_YGNodeStyleSetMaxHeightFitContentJNI(long nativePointer);
130+
static native void jni_YGNodeStyleSetMaxHeightStretchJNI(long nativePointer);
110131
static native float jni_YGNodeStyleGetAspectRatioJNI(long nativePointer);
111132
static native void jni_YGNodeStyleSetAspectRatioJNI(long nativePointer, float aspectRatio);
112133
static native float jni_YGNodeStyleGetGapJNI(long nativePointer, int gutter);

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public interface Inputs {
124124

125125
public abstract void setFlexBasisAuto();
126126

127+
public abstract void setFlexBasisMaxContent();
128+
129+
public abstract void setFlexBasisFitContent();
130+
131+
public abstract void setFlexBasisStretch();
132+
127133
public abstract YogaValue getMargin(YogaEdge edge);
128134

129135
public abstract void setMargin(YogaEdge edge, float margin);
@@ -158,6 +164,12 @@ public interface Inputs {
158164

159165
public abstract void setWidthAuto();
160166

167+
public abstract void setWidthMaxContent();
168+
169+
public abstract void setWidthFitContent();
170+
171+
public abstract void setWidthStretch();
172+
161173
public abstract YogaValue getHeight();
162174

163175
public abstract void setHeight(float height);
@@ -166,30 +178,60 @@ public interface Inputs {
166178

167179
public abstract void setHeightAuto();
168180

181+
public abstract void setHeightMaxContent();
182+
183+
public abstract void setHeightFitContent();
184+
185+
public abstract void setHeightStretch();
186+
169187
public abstract YogaValue getMinWidth();
170188

171189
public abstract void setMinWidth(float minWidth);
172190

173191
public abstract void setMinWidthPercent(float percent);
174192

193+
public abstract void setMinWidthMaxContent();
194+
195+
public abstract void setMinWidthFitContent();
196+
197+
public abstract void setMinWidthStretch();
198+
175199
public abstract YogaValue getMinHeight();
176200

177201
public abstract void setMinHeight(float minHeight);
178202

179203
public abstract void setMinHeightPercent(float percent);
180204

205+
public abstract void setMinHeightMaxContent();
206+
207+
public abstract void setMinHeightFitContent();
208+
209+
public abstract void setMinHeightStretch();
210+
181211
public abstract YogaValue getMaxWidth();
182212

183213
public abstract void setMaxWidth(float maxWidth);
184214

185215
public abstract void setMaxWidthPercent(float percent);
186216

217+
public abstract void setMaxWidthMaxContent();
218+
219+
public abstract void setMaxWidthFitContent();
220+
221+
public abstract void setMaxWidthStretch();
222+
187223
public abstract YogaValue getMaxHeight();
188224

189225
public abstract void setMaxHeight(float maxheight);
190226

191227
public abstract void setMaxHeightPercent(float percent);
192228

229+
public abstract void setMaxHeightMaxContent();
230+
231+
public abstract void setMaxHeightFitContent();
232+
233+
public abstract void setMaxHeightStretch();
234+
193235
public abstract float getAspectRatio();
194236

195237
public abstract void setAspectRatio(float aspectRatio);

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,18 @@ public void setFlexBasisAuto() {
373373
YogaNative.jni_YGNodeStyleSetFlexBasisAutoJNI(mNativePointer);
374374
}
375375

376+
public void setFlexBasisMaxContent() {
377+
YogaNative.jni_YGNodeStyleSetFlexBasisMaxContentJNI(mNativePointer);
378+
}
379+
380+
public void setFlexBasisFitContent() {
381+
YogaNative.jni_YGNodeStyleSetFlexBasisFitContentJNI(mNativePointer);
382+
}
383+
384+
public void setFlexBasisStretch() {
385+
YogaNative.jni_YGNodeStyleSetFlexBasisStretchJNI(mNativePointer);
386+
}
387+
376388
public YogaValue getMargin(YogaEdge edge) {
377389
return valueFromLong(YogaNative.jni_YGNodeStyleGetMarginJNI(mNativePointer, edge.intValue()));
378390
}
@@ -441,6 +453,18 @@ public void setWidthAuto() {
441453
YogaNative.jni_YGNodeStyleSetWidthAutoJNI(mNativePointer);
442454
}
443455

456+
public void setWidthMaxContent() {
457+
YogaNative.jni_YGNodeStyleSetWidthMaxContentJNI(mNativePointer);
458+
}
459+
460+
public void setWidthFitContent() {
461+
YogaNative.jni_YGNodeStyleSetWidthFitContentJNI(mNativePointer);
462+
}
463+
464+
public void setWidthStretch() {
465+
YogaNative.jni_YGNodeStyleSetWidthStretchJNI(mNativePointer);
466+
}
467+
444468
public YogaValue getHeight() {
445469
return valueFromLong(YogaNative.jni_YGNodeStyleGetHeightJNI(mNativePointer));
446470
}
@@ -457,6 +481,18 @@ public void setHeightAuto() {
457481
YogaNative.jni_YGNodeStyleSetHeightAutoJNI(mNativePointer);
458482
}
459483

484+
public void setHeightMaxContent() {
485+
YogaNative.jni_YGNodeStyleSetHeightMaxContentJNI(mNativePointer);
486+
}
487+
488+
public void setHeightFitContent() {
489+
YogaNative.jni_YGNodeStyleSetHeightFitContentJNI(mNativePointer);
490+
}
491+
492+
public void setHeightStretch() {
493+
YogaNative.jni_YGNodeStyleSetHeightStretchJNI(mNativePointer);
494+
}
495+
460496
public YogaValue getMinWidth() {
461497
return valueFromLong(YogaNative.jni_YGNodeStyleGetMinWidthJNI(mNativePointer));
462498
}
@@ -469,6 +505,18 @@ public void setMinWidthPercent(float percent) {
469505
YogaNative.jni_YGNodeStyleSetMinWidthPercentJNI(mNativePointer, percent);
470506
}
471507

508+
public void setMinWidthMaxContent() {
509+
YogaNative.jni_YGNodeStyleSetMinWidthMaxContentJNI(mNativePointer);
510+
}
511+
512+
public void setMinWidthFitContent() {
513+
YogaNative.jni_YGNodeStyleSetMinWidthFitContentJNI(mNativePointer);
514+
}
515+
516+
public void setMinWidthStretch() {
517+
YogaNative.jni_YGNodeStyleSetMinWidthStretchJNI(mNativePointer);
518+
}
519+
472520
public YogaValue getMinHeight() {
473521
return valueFromLong(YogaNative.jni_YGNodeStyleGetMinHeightJNI(mNativePointer));
474522
}
@@ -481,6 +529,18 @@ public void setMinHeightPercent(float percent) {
481529
YogaNative.jni_YGNodeStyleSetMinHeightPercentJNI(mNativePointer, percent);
482530
}
483531

532+
public void setMinHeightMaxContent() {
533+
YogaNative.jni_YGNodeStyleSetMinHeightMaxContentJNI(mNativePointer);
534+
}
535+
536+
public void setMinHeightFitContent() {
537+
YogaNative.jni_YGNodeStyleSetMinHeightFitContentJNI(mNativePointer);
538+
}
539+
540+
public void setMinHeightStretch() {
541+
YogaNative.jni_YGNodeStyleSetMinHeightStretchJNI(mNativePointer);
542+
}
543+
484544
public YogaValue getMaxWidth() {
485545
return valueFromLong(YogaNative.jni_YGNodeStyleGetMaxWidthJNI(mNativePointer));
486546
}
@@ -493,6 +553,18 @@ public void setMaxWidthPercent(float percent) {
493553
YogaNative.jni_YGNodeStyleSetMaxWidthPercentJNI(mNativePointer, percent);
494554
}
495555

556+
public void setMaxWidthMaxContent() {
557+
YogaNative.jni_YGNodeStyleSetMaxWidthMaxContentJNI(mNativePointer);
558+
}
559+
560+
public void setMaxWidthFitContent() {
561+
YogaNative.jni_YGNodeStyleSetMaxWidthFitContentJNI(mNativePointer);
562+
}
563+
564+
public void setMaxWidthStretch() {
565+
YogaNative.jni_YGNodeStyleSetMaxWidthStretchJNI(mNativePointer);
566+
}
567+
496568
public YogaValue getMaxHeight() {
497569
return valueFromLong(YogaNative.jni_YGNodeStyleGetMaxHeightJNI(mNativePointer));
498570
}
@@ -505,6 +577,18 @@ public void setMaxHeightPercent(float percent) {
505577
YogaNative.jni_YGNodeStyleSetMaxHeightPercentJNI(mNativePointer, percent);
506578
}
507579

580+
public void setMaxHeightMaxContent() {
581+
YogaNative.jni_YGNodeStyleSetMaxHeightMaxContentJNI(mNativePointer);
582+
}
583+
584+
public void setMaxHeightFitContent() {
585+
YogaNative.jni_YGNodeStyleSetMaxHeightFitContentJNI(mNativePointer);
586+
}
587+
588+
public void setMaxHeightStretch() {
589+
YogaNative.jni_YGNodeStyleSetMaxHeightStretchJNI(mNativePointer);
590+
}
591+
508592
public float getAspectRatio() {
509593
return YogaNative.jni_YGNodeStyleGetAspectRatioJNI(mNativePointer);
510594
}

0 commit comments

Comments
 (0)