Skip to content

Commit fcdd6a7

Browse files
CSS Grid 5/9: Java/Kotlin bindings
Summary: Add Java/Kotlin bindings for CSS Grid support. Includes grid API classes (YogaGridTrackList, YogaGridTrackValue, YogaGridTrackType), JNI bridge updates, enum changes (YogaDisplay, YogaAlign, YogaJustify). Also includes React Native Android mirror of all Java/Kotlin changes. Differential Revision: D93946256
1 parent 96e0d1a commit fcdd6a7

7 files changed

Lines changed: 695 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.yoga;
9+
10+
import java.util.ArrayList;
11+
import java.util.Collections;
12+
import java.util.List;
13+
14+
/**
15+
* Represents a list of grid tracks for use with grid-template-rows/columns.
16+
*/
17+
public class YogaGridTrackList {
18+
private final List<YogaGridTrackValue> tracks;
19+
20+
public YogaGridTrackList() {
21+
this.tracks = new ArrayList<>();
22+
}
23+
24+
public void addTrack(YogaGridTrackValue track) {
25+
tracks.add(track);
26+
}
27+
28+
public List<YogaGridTrackValue> getTracks() {
29+
return Collections.unmodifiableList(tracks);
30+
}
31+
32+
public int size() {
33+
return tracks.size();
34+
}
35+
36+
public YogaGridTrackValue get(int index) {
37+
return tracks.get(index);
38+
}
39+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.yoga;
9+
10+
/**
11+
* Represents a grid track value for use with grid-template-rows/columns.
12+
*/
13+
public class YogaGridTrackValue {
14+
public enum Type {
15+
AUTO,
16+
POINTS,
17+
PERCENT,
18+
FR,
19+
MINMAX
20+
}
21+
22+
private final Type type;
23+
private final float value;
24+
private final YogaGridTrackValue minValue;
25+
private final YogaGridTrackValue maxValue;
26+
27+
private YogaGridTrackValue(Type type, float value) {
28+
this.type = type;
29+
this.value = value;
30+
this.minValue = null;
31+
this.maxValue = null;
32+
}
33+
34+
private YogaGridTrackValue(YogaGridTrackValue min, YogaGridTrackValue max) {
35+
this.type = Type.MINMAX;
36+
this.value = 0;
37+
this.minValue = min;
38+
this.maxValue = max;
39+
}
40+
41+
public static YogaGridTrackValue auto() {
42+
return new YogaGridTrackValue(Type.AUTO, 0);
43+
}
44+
45+
public static YogaGridTrackValue points(float points) {
46+
return new YogaGridTrackValue(Type.POINTS, points);
47+
}
48+
49+
public static YogaGridTrackValue percent(float percent) {
50+
return new YogaGridTrackValue(Type.PERCENT, percent);
51+
}
52+
53+
public static YogaGridTrackValue fr(float fr) {
54+
return new YogaGridTrackValue(Type.FR, fr);
55+
}
56+
57+
public static YogaGridTrackValue minMax(YogaGridTrackValue min, YogaGridTrackValue max) {
58+
return new YogaGridTrackValue(min, max);
59+
}
60+
61+
public Type getType() {
62+
return type;
63+
}
64+
65+
public float getValue() {
66+
return value;
67+
}
68+
69+
public YogaGridTrackValue getMinValue() {
70+
return minValue;
71+
}
72+
73+
public YogaGridTrackValue getMaxValue() {
74+
return maxValue;
75+
}
76+
}

java/com/facebook/yoga/YogaNative.kt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ public object YogaNative {
9898
@JvmStatic
9999
public external fun jni_YGNodeStyleSetJustifyContentJNI(nativePointer: Long, justifyContent: Int)
100100

101+
@JvmStatic public external fun jni_YGNodeStyleGetJustifyItemsJNI(nativePointer: Long): Int
102+
103+
@JvmStatic
104+
public external fun jni_YGNodeStyleSetJustifyItemsJNI(nativePointer: Long, justifyItems: Int)
105+
106+
@JvmStatic public external fun jni_YGNodeStyleGetJustifySelfJNI(nativePointer: Long): Int
107+
108+
@JvmStatic
109+
public external fun jni_YGNodeStyleSetJustifySelfJNI(nativePointer: Long, justifySelf: Int)
110+
101111
@JvmStatic public external fun jni_YGNodeStyleGetAlignItemsJNI(nativePointer: Long): Int
102112

103113
@JvmStatic
@@ -328,4 +338,68 @@ public object YogaNative {
328338
nativePointer: Long,
329339
alwaysFormContainingBlock: Boolean,
330340
)
341+
342+
@JvmStatic
343+
public external fun jni_YGNodeStyleSetGridTemplateColumnsJNI(
344+
nativePointer: Long,
345+
types: IntArray,
346+
values: FloatArray,
347+
minTypes: IntArray,
348+
minValues: FloatArray,
349+
maxTypes: IntArray,
350+
maxValues: FloatArray,
351+
)
352+
353+
@JvmStatic
354+
public external fun jni_YGNodeStyleSetGridTemplateRowsJNI(
355+
nativePointer: Long,
356+
types: IntArray,
357+
values: FloatArray,
358+
minTypes: IntArray,
359+
minValues: FloatArray,
360+
maxTypes: IntArray,
361+
maxValues: FloatArray,
362+
)
363+
364+
@JvmStatic
365+
public external fun jni_YGNodeStyleSetGridAutoColumnsJNI(
366+
nativePointer: Long,
367+
types: IntArray,
368+
values: FloatArray,
369+
minTypes: IntArray,
370+
minValues: FloatArray,
371+
maxTypes: IntArray,
372+
maxValues: FloatArray,
373+
)
374+
375+
@JvmStatic
376+
public external fun jni_YGNodeStyleSetGridAutoRowsJNI(
377+
nativePointer: Long,
378+
types: IntArray,
379+
values: FloatArray,
380+
minTypes: IntArray,
381+
minValues: FloatArray,
382+
maxTypes: IntArray,
383+
maxValues: FloatArray,
384+
)
385+
386+
@JvmStatic
387+
public external fun jni_YGNodeStyleSetGridColumnStartJNI(nativePointer: Long, value: Int)
388+
389+
@JvmStatic
390+
public external fun jni_YGNodeStyleSetGridColumnStartSpanJNI(nativePointer: Long, span: Int)
391+
392+
@JvmStatic public external fun jni_YGNodeStyleSetGridColumnEndJNI(nativePointer: Long, value: Int)
393+
394+
@JvmStatic
395+
public external fun jni_YGNodeStyleSetGridColumnEndSpanJNI(nativePointer: Long, span: Int)
396+
397+
@JvmStatic public external fun jni_YGNodeStyleSetGridRowStartJNI(nativePointer: Long, value: Int)
398+
399+
@JvmStatic
400+
public external fun jni_YGNodeStyleSetGridRowStartSpanJNI(nativePointer: Long, span: Int)
401+
402+
@JvmStatic public external fun jni_YGNodeStyleSetGridRowEndJNI(nativePointer: Long, value: Int)
403+
404+
@JvmStatic public external fun jni_YGNodeStyleSetGridRowEndSpanJNI(nativePointer: Long, span: Int)
331405
}

java/com/facebook/yoga/YogaNode.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public abstract class YogaNode : YogaProps {
6464

6565
abstract override var justifyContent: YogaJustify
6666

67+
abstract override var justifyItems: YogaJustify
68+
69+
abstract override var justifySelf: YogaJustify
70+
6771
abstract override var alignItems: YogaAlign
6872

6973
abstract override var alignSelf: YogaAlign
@@ -210,6 +214,30 @@ public abstract class YogaNode : YogaProps {
210214

211215
public abstract fun setGapPercent(gutter: YogaGutter, gapLength: Float)
212216

217+
public abstract fun setGridTemplateColumns(trackList: YogaGridTrackList)
218+
219+
public abstract fun setGridTemplateRows(trackList: YogaGridTrackList)
220+
221+
public abstract fun setGridAutoColumns(trackList: YogaGridTrackList)
222+
223+
public abstract fun setGridAutoRows(trackList: YogaGridTrackList)
224+
225+
public abstract fun setGridColumnStart(value: Int)
226+
227+
public abstract fun setGridColumnStartSpan(span: Int)
228+
229+
public abstract fun setGridColumnEnd(value: Int)
230+
231+
public abstract fun setGridColumnEndSpan(span: Int)
232+
233+
public abstract fun setGridRowStart(value: Int)
234+
235+
public abstract fun setGridRowStartSpan(span: Int)
236+
237+
public abstract fun setGridRowEnd(value: Int)
238+
239+
public abstract fun setGridRowEndSpan(span: Int)
240+
213241
public abstract val layoutX: Float
214242

215243
public abstract val layoutY: Float

0 commit comments

Comments
 (0)