From b4a1de321679e515a94a9bc5a34a22256088f196 Mon Sep 17 00:00:00 2001 From: J8118 Date: Thu, 9 Apr 2026 09:48:14 +0400 Subject: [PATCH 1/2] Expose HadOverflow property in JavaScript bindings Add getComputedHadOverflow() method and include hadOverflow in the Layout type returned by getComputedLayout(). This exposes the existing C API function YGNodeLayoutGetHadOverflow() which was previously missing from the JS bindings. Closes https://github.com/facebook/yoga/issues/1773 --- javascript/src/wrapAssembly.ts | 7 ++ javascript/tests/YGHadOverflowTest.test.ts | 114 +++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 javascript/tests/YGHadOverflowTest.test.ts diff --git a/javascript/src/wrapAssembly.ts b/javascript/src/wrapAssembly.ts index cbb51a4564..f6689a2ca9 100644 --- a/javascript/src/wrapAssembly.ts +++ b/javascript/src/wrapAssembly.ts @@ -35,6 +35,7 @@ type Layout = { bottom: number; width: number; height: number; + hadOverflow: boolean; }; type Size = { @@ -85,6 +86,7 @@ export type Node = { getChildCount(): number; getComputedBorder(edge: Edge): number; getComputedBottom(): number; + getComputedHadOverflow(): boolean; getComputedHeight(): number; getComputedLayout(): Layout; getComputedLeft(): number; @@ -965,6 +967,10 @@ export default function wrapAssembly(lib: any): Yoga { return lib._YGNodeLayoutGetHeight(this._ptr); } + getComputedHadOverflow(): boolean { + return !!lib._YGNodeLayoutGetHadOverflow(this._ptr); + } + getComputedLayout(): Layout { return { left: lib._YGNodeLayoutGetLeft(this._ptr), @@ -973,6 +979,7 @@ export default function wrapAssembly(lib: any): Yoga { bottom: lib._YGNodeLayoutGetBottom(this._ptr), width: lib._YGNodeLayoutGetWidth(this._ptr), height: lib._YGNodeLayoutGetHeight(this._ptr), + hadOverflow: !!lib._YGNodeLayoutGetHadOverflow(this._ptr), }; } diff --git a/javascript/tests/YGHadOverflowTest.test.ts b/javascript/tests/YGHadOverflowTest.test.ts new file mode 100644 index 0000000000..b259d9ea17 --- /dev/null +++ b/javascript/tests/YGHadOverflowTest.test.ts @@ -0,0 +1,114 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import Yoga from 'yoga-layout'; +import {Direction, FlexDirection, Wrap} from 'yoga-layout'; + +test('children_overflow_no_wrap_and_no_flex_children', () => { + const root = Yoga.Node.create(); + root.setWidth(200); + root.setHeight(100); + root.setFlexDirection(FlexDirection.Column); + root.setFlexWrap(Wrap.NoWrap); + + const child0 = Yoga.Node.create(); + child0.setWidth(80); + child0.setHeight(40); + child0.setMargin(Yoga.EDGE_TOP, 10); + child0.setMargin(Yoga.EDGE_BOTTOM, 15); + root.insertChild(child0, 0); + + const child1 = Yoga.Node.create(); + child1.setWidth(80); + child1.setHeight(40); + child1.setMargin(Yoga.EDGE_BOTTOM, 5); + root.insertChild(child1, 1); + + root.calculateLayout(200, 100, Direction.LTR); + + expect(root.getComputedHadOverflow()).toBe(true); + +}); + +test('no_overflow_no_wrap_and_flex_children', () => { + const root = Yoga.Node.create(); + root.setWidth(200); + root.setHeight(100); + root.setFlexDirection(FlexDirection.Column); + root.setFlexWrap(Wrap.NoWrap); + + const child0 = Yoga.Node.create(); + child0.setWidth(80); + child0.setHeight(40); + child0.setMargin(Yoga.EDGE_TOP, 10); + child0.setMargin(Yoga.EDGE_BOTTOM, 10); + root.insertChild(child0, 0); + + const child1 = Yoga.Node.create(); + child1.setWidth(80); + child1.setHeight(40); + child1.setMargin(Yoga.EDGE_BOTTOM, 5); + child1.setFlexShrink(1); + root.insertChild(child1, 1); + + root.calculateLayout(200, 100, Direction.LTR); + + expect(root.getComputedHadOverflow()).toBe(false); + +}); + +test('hadOverflow_gets_reset_if_no_longer_valid', () => { + const root = Yoga.Node.create(); + root.setWidth(200); + root.setHeight(100); + root.setFlexDirection(FlexDirection.Column); + root.setFlexWrap(Wrap.NoWrap); + + const child0 = Yoga.Node.create(); + child0.setWidth(80); + child0.setHeight(40); + child0.setMargin(Yoga.EDGE_TOP, 10); + child0.setMargin(Yoga.EDGE_BOTTOM, 10); + root.insertChild(child0, 0); + + const child1 = Yoga.Node.create(); + child1.setWidth(80); + child1.setHeight(40); + child1.setMargin(Yoga.EDGE_BOTTOM, 5); + root.insertChild(child1, 1); + + root.calculateLayout(200, 100, Direction.LTR); + expect(root.getComputedHadOverflow()).toBe(true); + + child1.setFlexShrink(1); + root.calculateLayout(200, 100, Direction.LTR); + expect(root.getComputedHadOverflow()).toBe(false); + +}); + +test('hadOverflow_included_in_getComputedLayout', () => { + const root = Yoga.Node.create(); + root.setWidth(200); + root.setHeight(100); + root.setFlexDirection(FlexDirection.Column); + + const child0 = Yoga.Node.create(); + child0.setWidth(80); + child0.setHeight(80); + root.insertChild(child0, 0); + + const child1 = Yoga.Node.create(); + child1.setWidth(80); + child1.setHeight(80); + root.insertChild(child1, 1); + + root.calculateLayout(200, 100, Direction.LTR); + + const layout = root.getComputedLayout(); + expect(layout.hadOverflow).toBe(true); + +}); From cea8d215361efa47bc3d2de888dca57763b55072 Mon Sep 17 00:00:00 2001 From: J8118 Date: Thu, 9 Apr 2026 19:39:18 +0400 Subject: [PATCH 2/2] Fix lint errors in YGHadOverflowTest: remove extra blank lines --- javascript/tests/YGHadOverflowTest.test.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/javascript/tests/YGHadOverflowTest.test.ts b/javascript/tests/YGHadOverflowTest.test.ts index b259d9ea17..c768042c1d 100644 --- a/javascript/tests/YGHadOverflowTest.test.ts +++ b/javascript/tests/YGHadOverflowTest.test.ts @@ -31,7 +31,6 @@ test('children_overflow_no_wrap_and_no_flex_children', () => { root.calculateLayout(200, 100, Direction.LTR); expect(root.getComputedHadOverflow()).toBe(true); - }); test('no_overflow_no_wrap_and_flex_children', () => { @@ -58,7 +57,6 @@ test('no_overflow_no_wrap_and_flex_children', () => { root.calculateLayout(200, 100, Direction.LTR); expect(root.getComputedHadOverflow()).toBe(false); - }); test('hadOverflow_gets_reset_if_no_longer_valid', () => { @@ -87,7 +85,6 @@ test('hadOverflow_gets_reset_if_no_longer_valid', () => { child1.setFlexShrink(1); root.calculateLayout(200, 100, Direction.LTR); expect(root.getComputedHadOverflow()).toBe(false); - }); test('hadOverflow_included_in_getComputedLayout', () => { @@ -110,5 +107,4 @@ test('hadOverflow_included_in_getComputedLayout', () => { const layout = root.getComputedLayout(); expect(layout.hadOverflow).toBe(true); - });