Skip to content

Commit 02d8ec6

Browse files
J8118meta-codesync[bot]
authored andcommitted
Expose HadOverflow property in JavaScript bindings (#1930)
Summary: The C API provides `YGNodeLayoutGetHadOverflow()` to check whether a node's layout had overflow, but this was not exposed in the JavaScript bindings. This PR adds: - `getComputedHadOverflow(): boolean` — standalone method on `Node` - `hadOverflow: boolean` field in the `Layout` type returned by `getComputedLayout()` The implementation follows the exact same pattern as existing layout getters (e.g., `getComputedWidth`, `getComputedHeight`) and boolean accessors (e.g., `hasNewLayout`). Closes #1773 Pull Request resolved: #1930 Test Plan: - Added `YGHadOverflowTest.test.ts` with 4 test cases ported from the C++ test suite (`tests/YGHadOverflowTest.cpp`): - Children overflow with no wrap and no flex → `hadOverflow` is true - No overflow with flex children that shrink → `hadOverflow` is false - Overflow flag resets when layout changes → true then false - `getComputedLayout()` includes `hadOverflow` field - Full test suite passes: 38 suites, 574 tests, 0 failures Reviewed By: NickGerleman Differential Revision: D100144528 Pulled By: fabriziocucci fbshipit-source-id: fb0f1bdefb17a27a85b32bef5ed82e25153be866
1 parent 21680f2 commit 02d8ec6

2 files changed

Lines changed: 117 additions & 0 deletions

File tree

javascript/src/wrapAssembly.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Layout = {
3535
bottom: number;
3636
width: number;
3737
height: number;
38+
hadOverflow: boolean;
3839
};
3940

4041
type Size = {
@@ -85,6 +86,7 @@ export type Node = {
8586
getChildCount(): number;
8687
getComputedBorder(edge: Edge): number;
8788
getComputedBottom(): number;
89+
getComputedHadOverflow(): boolean;
8890
getComputedHeight(): number;
8991
getComputedLayout(): Layout;
9092
getComputedLeft(): number;
@@ -965,6 +967,10 @@ export default function wrapAssembly(lib: any): Yoga {
965967
return lib._YGNodeLayoutGetHeight(this._ptr);
966968
}
967969

970+
getComputedHadOverflow(): boolean {
971+
return !!lib._YGNodeLayoutGetHadOverflow(this._ptr);
972+
}
973+
968974
getComputedLayout(): Layout {
969975
return {
970976
left: lib._YGNodeLayoutGetLeft(this._ptr),
@@ -973,6 +979,7 @@ export default function wrapAssembly(lib: any): Yoga {
973979
bottom: lib._YGNodeLayoutGetBottom(this._ptr),
974980
width: lib._YGNodeLayoutGetWidth(this._ptr),
975981
height: lib._YGNodeLayoutGetHeight(this._ptr),
982+
hadOverflow: !!lib._YGNodeLayoutGetHadOverflow(this._ptr),
976983
};
977984
}
978985

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
import Yoga from 'yoga-layout';
9+
import {Direction, FlexDirection, Wrap} from 'yoga-layout';
10+
11+
test('children_overflow_no_wrap_and_no_flex_children', () => {
12+
const root = Yoga.Node.create();
13+
root.setWidth(200);
14+
root.setHeight(100);
15+
root.setFlexDirection(FlexDirection.Column);
16+
root.setFlexWrap(Wrap.NoWrap);
17+
18+
const child0 = Yoga.Node.create();
19+
child0.setWidth(80);
20+
child0.setHeight(40);
21+
child0.setMargin(Yoga.EDGE_TOP, 10);
22+
child0.setMargin(Yoga.EDGE_BOTTOM, 15);
23+
root.insertChild(child0, 0);
24+
25+
const child1 = Yoga.Node.create();
26+
child1.setWidth(80);
27+
child1.setHeight(40);
28+
child1.setMargin(Yoga.EDGE_BOTTOM, 5);
29+
root.insertChild(child1, 1);
30+
31+
root.calculateLayout(200, 100, Direction.LTR);
32+
33+
expect(root.getComputedHadOverflow()).toBe(true);
34+
});
35+
36+
test('no_overflow_no_wrap_and_flex_children', () => {
37+
const root = Yoga.Node.create();
38+
root.setWidth(200);
39+
root.setHeight(100);
40+
root.setFlexDirection(FlexDirection.Column);
41+
root.setFlexWrap(Wrap.NoWrap);
42+
43+
const child0 = Yoga.Node.create();
44+
child0.setWidth(80);
45+
child0.setHeight(40);
46+
child0.setMargin(Yoga.EDGE_TOP, 10);
47+
child0.setMargin(Yoga.EDGE_BOTTOM, 10);
48+
root.insertChild(child0, 0);
49+
50+
const child1 = Yoga.Node.create();
51+
child1.setWidth(80);
52+
child1.setHeight(40);
53+
child1.setMargin(Yoga.EDGE_BOTTOM, 5);
54+
child1.setFlexShrink(1);
55+
root.insertChild(child1, 1);
56+
57+
root.calculateLayout(200, 100, Direction.LTR);
58+
59+
expect(root.getComputedHadOverflow()).toBe(false);
60+
});
61+
62+
test('hadOverflow_gets_reset_if_no_longer_valid', () => {
63+
const root = Yoga.Node.create();
64+
root.setWidth(200);
65+
root.setHeight(100);
66+
root.setFlexDirection(FlexDirection.Column);
67+
root.setFlexWrap(Wrap.NoWrap);
68+
69+
const child0 = Yoga.Node.create();
70+
child0.setWidth(80);
71+
child0.setHeight(40);
72+
child0.setMargin(Yoga.EDGE_TOP, 10);
73+
child0.setMargin(Yoga.EDGE_BOTTOM, 10);
74+
root.insertChild(child0, 0);
75+
76+
const child1 = Yoga.Node.create();
77+
child1.setWidth(80);
78+
child1.setHeight(40);
79+
child1.setMargin(Yoga.EDGE_BOTTOM, 5);
80+
root.insertChild(child1, 1);
81+
82+
root.calculateLayout(200, 100, Direction.LTR);
83+
expect(root.getComputedHadOverflow()).toBe(true);
84+
85+
child1.setFlexShrink(1);
86+
root.calculateLayout(200, 100, Direction.LTR);
87+
expect(root.getComputedHadOverflow()).toBe(false);
88+
});
89+
90+
test('hadOverflow_included_in_getComputedLayout', () => {
91+
const root = Yoga.Node.create();
92+
root.setWidth(200);
93+
root.setHeight(100);
94+
root.setFlexDirection(FlexDirection.Column);
95+
96+
const child0 = Yoga.Node.create();
97+
child0.setWidth(80);
98+
child0.setHeight(80);
99+
root.insertChild(child0, 0);
100+
101+
const child1 = Yoga.Node.create();
102+
child1.setWidth(80);
103+
child1.setHeight(80);
104+
root.insertChild(child1, 1);
105+
106+
root.calculateLayout(200, 100, Direction.LTR);
107+
108+
const layout = root.getComputedLayout();
109+
expect(layout.hadOverflow).toBe(true);
110+
});

0 commit comments

Comments
 (0)