Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions javascript/src/wrapAssembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Layout = {
bottom: number;
width: number;
height: number;
hadOverflow: boolean;
};

type Size = {
Expand Down Expand Up @@ -85,6 +86,7 @@ export type Node = {
getChildCount(): number;
getComputedBorder(edge: Edge): number;
getComputedBottom(): number;
getComputedHadOverflow(): boolean;
getComputedHeight(): number;
getComputedLayout(): Layout;
getComputedLeft(): number;
Expand Down Expand Up @@ -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),
Expand All @@ -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),
};
}

Expand Down
110 changes: 110 additions & 0 deletions javascript/tests/YGHadOverflowTest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* 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);
});
Loading