From dd96ce141cf3fe80f904474fc4852cab3c428b34 Mon Sep 17 00:00:00 2001 From: Jesse Wilson at Work Date: Wed, 23 Oct 2024 17:17:06 -0400 Subject: [PATCH] Fix the centering math in Box on Android (#2406) The code was incorrectly not subtracting margins off before centering. --- .../src/main/kotlin/app/cash/redwood/layout/view/ViewBox.kt | 4 ++-- ...od.layout.view_ViewBoxTest_RTL_testChildExplicitHeight.png | 4 ++-- ...od.layout.view_ViewBoxTest_RTL_testMarginsAndAlignment.png | 4 ++-- ...edwood.layout.view_ViewBoxTest_testChildExplicitHeight.png | 4 ++-- ...edwood.layout.view_ViewBoxTest_testMarginsAndAlignment.png | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewBox.kt b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewBox.kt index bd0de8026a..564deae129 100644 --- a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewBox.kt +++ b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewBox.kt @@ -298,7 +298,7 @@ private class Measurer { val left = when { horizontalAlignment == CrossAxisAlignment.Center -> { - marginLeft + (frameWidth - width) / 2 + marginLeft + (frameWidth - width - marginWidth) / 2 } alignRight -> { (boxMarginStart + frameWidth + boxMarginEnd) - marginRight - width @@ -308,7 +308,7 @@ private class Measurer { val top = when (verticalAlignment) { CrossAxisAlignment.Center -> { - boxMarginTop + marginTop + (frameHeight - height) / 2 + boxMarginTop + marginTop + (frameHeight - height - marginHeight) / 2 } CrossAxisAlignment.End -> { boxMarginTop + frameHeight - marginBottom - height diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_RTL_testChildExplicitHeight.png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_RTL_testChildExplicitHeight.png index 810688cf52..2583f5dd7a 100644 --- a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_RTL_testChildExplicitHeight.png +++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_RTL_testChildExplicitHeight.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:204af710a45fe5d2b69be98acb936b7f7fdd098e63541d7cf6bb1300254177e8 -size 5746 +oid sha256:8d32671f1f4f6af9f945fbfcd859e31331757182ea99ea9db2842a26b42ddd17 +size 5673 diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_RTL_testMarginsAndAlignment.png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_RTL_testMarginsAndAlignment.png index 58f739c1cf..0b9922dade 100644 --- a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_RTL_testMarginsAndAlignment.png +++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_RTL_testMarginsAndAlignment.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3204ac7fd815cfa3f5f078c4ac79538a6646e16281a9cb06842f8349b88462d5 -size 9474 +oid sha256:645140894515b335044944505668607041bdbf02cbc54eb1bc5f701fcdef655f +size 9534 diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_testChildExplicitHeight.png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_testChildExplicitHeight.png index c398b348fa..c84c279878 100644 --- a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_testChildExplicitHeight.png +++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_testChildExplicitHeight.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:15316752a6c11a86eac5f0ff7313315439b232fb9beab7a8aaed5f9cbd71227d -size 5737 +oid sha256:a1e3c2a6367481d9ea8a309207b548edf5b3d35e234b484b0c94fc43bc0bd54a +size 5641 diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_testMarginsAndAlignment.png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_testMarginsAndAlignment.png index 6bd387d011..dff28d9173 100644 --- a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_testMarginsAndAlignment.png +++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewBoxTest_testMarginsAndAlignment.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bb2dc0c8bddaa5591399db9a3fcbbf3ae66567737b230347968dc9849066febb -size 9481 +oid sha256:a89b8efb1fc80c9abcc210291f970f7f377c46c970f5d9e65b0d2d54025d7f97 +size 9545