Skip to content

Commit 8d5435f

Browse files
fix js tests
1 parent bf7f8a5 commit 8d5435f

309 files changed

Lines changed: 69232 additions & 79 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"editor.formatOnSave": true,
33
"editor.codeActionsOnSave": {
4-
"source.fixAll.eslint": "explicit"
4+
"source.fixAll.eslint": true
55
},
66
"eslint.format.enable": true,
77
"eslint.packageManager": "yarn",
@@ -16,5 +16,5 @@
1616
{
1717
"mode": "auto"
1818
}
19-
],
19+
]
2020
}

gentest/fixtures/grid/grid_fr_span_2_proportion_with_non_spanned_track.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

gentest/fixtures/grid/grid_minmax_auto_percent_indefinite.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

gentest/fixtures/grid/xgrid_fr_span_2_proportion_sub_1_sum_with_non_spanned_track.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

gentest/gentest-javascript.js

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,61 @@
77

88
/* global Emitter:readable */
99

10+
function parseGridTrackListJS(value) {
11+
if (!value || value === 'none') {
12+
return null;
13+
}
14+
15+
if (typeof value !== 'string') {
16+
return null;
17+
}
18+
19+
const tracks = [];
20+
const parts = value.trim().split(/\s+/);
21+
22+
let i = 0;
23+
while (i < parts.length) {
24+
const part = parts[i];
25+
26+
if (part.startsWith('minmax(')) {
27+
let minmaxStr = part;
28+
while (!minmaxStr.includes(')') && i < parts.length - 1) {
29+
i++;
30+
minmaxStr += ' ' + parts[i];
31+
}
32+
33+
const match = minmaxStr.match(/minmax\(([^,]+),\s*([^)]+)\)/);
34+
if (match) {
35+
const min = match[1].trim();
36+
const max = match[2].trim();
37+
tracks.push({
38+
type: 'minmax',
39+
min: parseGridTrackValueJS(min),
40+
max: parseGridTrackValueJS(max),
41+
});
42+
}
43+
} else {
44+
tracks.push(parseGridTrackValueJS(part));
45+
}
46+
i++;
47+
}
48+
49+
return tracks;
50+
}
51+
52+
function parseGridTrackValueJS(value) {
53+
if (value === 'auto') {
54+
return {type: 'auto'};
55+
} else if (value.endsWith('px')) {
56+
return {type: 'points', value: parseFloat(value)};
57+
} else if (value.endsWith('%')) {
58+
return {type: 'percent', value: parseFloat(value)};
59+
} else if (value.endsWith('fr')) {
60+
return {type: 'fr', value: parseFloat(value)};
61+
}
62+
return {type: 'auto'};
63+
}
64+
1065
const JavascriptEmitter = function () {
1166
Emitter.call(this, 'js', ' ');
1267
};
@@ -463,7 +518,8 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
463518
},
464519

465520
YGNodeStyleSetGridTemplateRows: {
466-
value: function (nodeName, tracks) {
521+
value: function (nodeName, value) {
522+
const tracks = parseGridTrackListJS(value);
467523
if (!tracks || tracks.length === 0) {
468524
return;
469525
}
@@ -490,7 +546,8 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
490546
},
491547

492548
YGNodeStyleSetGridTemplateColumns: {
493-
value: function (nodeName, tracks) {
549+
value: function (nodeName, value) {
550+
const tracks = parseGridTrackListJS(value);
494551
if (!tracks || tracks.length === 0) {
495552
return;
496553
}
@@ -565,7 +622,8 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
565622
},
566623

567624
YGNodeStyleSetGridAutoColumns: {
568-
value: function (nodeName, tracks) {
625+
value: function (nodeName, value) {
626+
const tracks = parseGridTrackListJS(value);
569627
if (!tracks || tracks.length === 0) {
570628
return;
571629
}
@@ -590,7 +648,8 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
590648
},
591649

592650
YGNodeStyleSetGridAutoRows: {
593-
value: function (nodeName, tracks) {
651+
value: function (nodeName, value) {
652+
const tracks = parseGridTrackListJS(value);
594653
if (!tracks || tracks.length === 0) {
595654
return;
596655
}
@@ -624,11 +683,9 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
624683
track.value + 'px',
625684
)}}`;
626685
case 'percent':
627-
return `{type: 'percent', value: ${toValueJavascript(
628-
track.value + '%',
629-
)}}`;
686+
return `{type: 'percent', value: ${track.value}}`;
630687
case 'fr':
631-
return `{type: 'fr', value: ${toValueJavascript(track.value)}}`;
688+
return `{type: 'fr', value: ${track.value}}`;
632689
default:
633690
return `{type: 'auto'}`;
634691
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.List;
12+
13+
/**
14+
* Represents a list of grid tracks for use with grid-template-rows/columns.
15+
*/
16+
public class YogaGridTrackList {
17+
private final List<YogaGridTrackValue> tracks;
18+
19+
public YogaGridTrackList() {
20+
this.tracks = new ArrayList<>();
21+
}
22+
23+
public void addTrack(YogaGridTrackValue track) {
24+
tracks.add(track);
25+
}
26+
27+
public List<YogaGridTrackValue> getTracks() {
28+
return tracks;
29+
}
30+
31+
public int size() {
32+
return tracks.size();
33+
}
34+
35+
public YogaGridTrackValue get(int index) {
36+
return tracks.get(index);
37+
}
38+
}
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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,72 @@ public object YogaNative {
328328
nativePointer: Long,
329329
alwaysFormContainingBlock: Boolean,
330330
)
331+
332+
@JvmStatic
333+
public external fun jni_YGNodeStyleSetGridTemplateColumnsJNI(
334+
nativePointer: Long,
335+
types: IntArray,
336+
values: FloatArray,
337+
minTypes: IntArray,
338+
minValues: FloatArray,
339+
maxTypes: IntArray,
340+
maxValues: FloatArray,
341+
)
342+
343+
@JvmStatic
344+
public external fun jni_YGNodeStyleSetGridTemplateRowsJNI(
345+
nativePointer: Long,
346+
types: IntArray,
347+
values: FloatArray,
348+
minTypes: IntArray,
349+
minValues: FloatArray,
350+
maxTypes: IntArray,
351+
maxValues: FloatArray,
352+
)
353+
354+
@JvmStatic
355+
public external fun jni_YGNodeStyleSetGridAutoColumnsJNI(
356+
nativePointer: Long,
357+
types: IntArray,
358+
values: FloatArray,
359+
minTypes: IntArray,
360+
minValues: FloatArray,
361+
maxTypes: IntArray,
362+
maxValues: FloatArray,
363+
)
364+
365+
@JvmStatic
366+
public external fun jni_YGNodeStyleSetGridAutoRowsJNI(
367+
nativePointer: Long,
368+
types: IntArray,
369+
values: FloatArray,
370+
minTypes: IntArray,
371+
minValues: FloatArray,
372+
maxTypes: IntArray,
373+
maxValues: FloatArray,
374+
)
375+
376+
@JvmStatic
377+
public external fun jni_YGNodeStyleSetGridColumnStartJNI(nativePointer: Long, value: Int)
378+
379+
@JvmStatic
380+
public external fun jni_YGNodeStyleSetGridColumnStartSpanJNI(nativePointer: Long, span: Int)
381+
382+
@JvmStatic
383+
public external fun jni_YGNodeStyleSetGridColumnEndJNI(nativePointer: Long, value: Int)
384+
385+
@JvmStatic
386+
public external fun jni_YGNodeStyleSetGridColumnEndSpanJNI(nativePointer: Long, span: Int)
387+
388+
@JvmStatic
389+
public external fun jni_YGNodeStyleSetGridRowStartJNI(nativePointer: Long, value: Int)
390+
391+
@JvmStatic
392+
public external fun jni_YGNodeStyleSetGridRowStartSpanJNI(nativePointer: Long, span: Int)
393+
394+
@JvmStatic
395+
public external fun jni_YGNodeStyleSetGridRowEndJNI(nativePointer: Long, value: Int)
396+
397+
@JvmStatic
398+
public external fun jni_YGNodeStyleSetGridRowEndSpanJNI(nativePointer: Long, span: Int)
331399
}

java/com/facebook/yoga/YogaNode.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,30 @@ public interface Inputs {
242242

243243
public abstract void setGapPercent(YogaGutter gutter, float gapLength);
244244

245+
public abstract void setGridTemplateColumns(YogaGridTrackList trackList);
246+
247+
public abstract void setGridTemplateRows(YogaGridTrackList trackList);
248+
249+
public abstract void setGridAutoColumns(YogaGridTrackList trackList);
250+
251+
public abstract void setGridAutoRows(YogaGridTrackList trackList);
252+
253+
public abstract void setGridColumnStart(int value);
254+
255+
public abstract void setGridColumnStartSpan(int span);
256+
257+
public abstract void setGridColumnEnd(int value);
258+
259+
public abstract void setGridColumnEndSpan(int span);
260+
261+
public abstract void setGridRowStart(int value);
262+
263+
public abstract void setGridRowStartSpan(int span);
264+
265+
public abstract void setGridRowEnd(int value);
266+
267+
public abstract void setGridRowEndSpan(int span);
268+
245269
public abstract float getLayoutX();
246270

247271
public abstract float getLayoutY();

0 commit comments

Comments
 (0)