From d1a33cd139fab4565b1fc691f5751c4af99d5849 Mon Sep 17 00:00:00 2001 From: Joel Arvidsson Date: Wed, 13 Oct 2021 16:59:17 -0700 Subject: [PATCH] Fix Android border positioning regression (#32398) Summary: https://github.com/facebook/react-native/issues/29099 introduced a regression where non-rounded borders on Android would render partly outside of the bounds of the view as I reported in https://github.com/facebook/react-native/issues/32393. This PR addresses that by rendering the borders completely inside the view like it works on iOS, previous version of RN and for rounded corners. ## Changelog [Android] [Fixed] - Fix Android border positioning regression Pull Request resolved: https://github.com/facebook/react-native/pull/32398 Test Plan: Rendering the following code (as reported in the issue) in the RN Tester app: ```jsx ``` |Before|After| |--|--| |![before](https://user-images.githubusercontent.com/378279/137178113-dd2fea7e-48c8-450b-be3a-92706ef93194.png)|![after](https://user-images.githubusercontent.com/378279/137178140-b5ce7b3d-d455-48a9-a57f-0f3194a65c9a.png)| Reviewed By: yungsters Differential Revision: D31623647 Pulled By: lunaleaps fbshipit-source-id: c38d172ae4a9dc48f800c63258223a59e2f621ed --- .../views/view/ReactViewBackgroundDrawable.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java index bed2251c84f..5d19b871392 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java @@ -1106,8 +1106,8 @@ public class ReactViewBackgroundDrawable extends Drawable { int width = Math.round(borderWidth.left); updatePathEffect(width); mPaint.setStrokeWidth(width); - mPathForSingleBorder.moveTo(left, top - borderWidth.top / 2); - mPathForSingleBorder.lineTo(left, bottom + borderWidth.bottom / 2); + mPathForSingleBorder.moveTo(left + width / 2, top); + mPathForSingleBorder.lineTo(left + width / 2, bottom); canvas.drawPath(mPathForSingleBorder, mPaint); } if (borderTop > 0) { @@ -1115,8 +1115,8 @@ public class ReactViewBackgroundDrawable extends Drawable { int width = Math.round(borderWidth.top); updatePathEffect(width); mPaint.setStrokeWidth(width); - mPathForSingleBorder.moveTo(left, top); - mPathForSingleBorder.lineTo(right, top); + mPathForSingleBorder.moveTo(left, top + width / 2); + mPathForSingleBorder.lineTo(right, top + width / 2); canvas.drawPath(mPathForSingleBorder, mPaint); } if (borderRight > 0) { @@ -1124,8 +1124,8 @@ public class ReactViewBackgroundDrawable extends Drawable { int width = Math.round(borderWidth.right); updatePathEffect(width); mPaint.setStrokeWidth(width); - mPathForSingleBorder.moveTo(right, top - borderWidth.top / 2); - mPathForSingleBorder.lineTo(right, bottom + borderWidth.bottom / 2); + mPathForSingleBorder.moveTo(right - width / 2, top); + mPathForSingleBorder.lineTo(right - width / 2, bottom); canvas.drawPath(mPathForSingleBorder, mPaint); } if (borderBottom > 0) { @@ -1133,8 +1133,8 @@ public class ReactViewBackgroundDrawable extends Drawable { int width = Math.round(borderWidth.bottom); updatePathEffect(width); mPaint.setStrokeWidth(width); - mPathForSingleBorder.moveTo(left, bottom); - mPathForSingleBorder.lineTo(right, bottom); + mPathForSingleBorder.moveTo(left, bottom - width / 2); + mPathForSingleBorder.lineTo(right, bottom - width / 2); canvas.drawPath(mPathForSingleBorder, mPaint); } }