Fix issue where padding for box sizing is resolved against wrong reference length (#1715)

Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1715

X-link: https://github.com/facebook/react-native/pull/46799

Content box impl had a bug where we resolved padding % against the same reference length as the dimensions. Padding should always be against containing block's width. This is also true for width, but not for height, which should be against containing block's height.

This just pipes the width into our box sizing functions.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D63787577

fbshipit-source-id: e512338770f25b66506cabab5a7cde8f04397ea0
This commit is contained in:
Joe Vilches
2024-10-04 17:07:05 -07:00
committed by Facebook GitHub Bot
parent 990ec920ad
commit e69fcb26bb
12 changed files with 171 additions and 103 deletions

View File

@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<48d3d46dec54df38f853a6fa17e6f0c6>>
* @generated SignedSource<<a841bb29f095097bae9635f62b9fb16d>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGBoxSizingTest.html
*/
@@ -499,14 +499,15 @@ test('box_sizing_content_box_padding_only_percent', () => {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Absolute);
root.setWidth(100);
root.setHeight(100);
root.setHeight(150);
const root_child0 = Yoga.Node.create(config);
root_child0.setPadding(Edge.Left, "10%");
root_child0.setPadding(Edge.Top, "10%");
root_child0.setPadding(Edge.Right, "10%");
root_child0.setPadding(Edge.Bottom, "10%");
root_child0.setWidth("50%");
root_child0.setWidth(50);
root_child0.setHeight(75);
root_child0.setBoxSizing(BoxSizing.ContentBox);
root.insertChild(root_child0, 0);
root.calculateLayout(undefined, undefined, Direction.LTR);
@@ -514,24 +515,24 @@ test('box_sizing_content_box_padding_only_percent', () => {
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(100);
expect(root.getComputedHeight()).toBe(100);
expect(root.getComputedHeight()).toBe(150);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(70);
expect(root_child0.getComputedHeight()).toBe(20);
expect(root_child0.getComputedHeight()).toBe(95);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(100);
expect(root.getComputedHeight()).toBe(100);
expect(root.getComputedHeight()).toBe(150);
expect(root_child0.getComputedLeft()).toBe(30);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(70);
expect(root_child0.getComputedHeight()).toBe(20);
expect(root_child0.getComputedHeight()).toBe(95);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
@@ -582,38 +583,39 @@ test('box_sizing_border_box_padding_only_percent', () => {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Absolute);
root.setWidth(100);
root.setHeight(100);
root.setHeight(150);
const root_child0 = Yoga.Node.create(config);
root_child0.setPadding(Edge.Left, "10%");
root_child0.setPadding(Edge.Top, "10%");
root_child0.setPadding(Edge.Right, "10%");
root_child0.setPadding(Edge.Bottom, "10%");
root_child0.setWidth("50%");
root_child0.setWidth(50);
root_child0.setHeight(75);
root.insertChild(root_child0, 0);
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(100);
expect(root.getComputedHeight()).toBe(100);
expect(root.getComputedHeight()).toBe(150);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(20);
expect(root_child0.getComputedHeight()).toBe(75);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(100);
expect(root.getComputedHeight()).toBe(100);
expect(root.getComputedHeight()).toBe(150);
expect(root_child0.getComputedLeft()).toBe(50);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(20);
expect(root_child0.getComputedHeight()).toBe(75);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();