From d8eef29094d4f536255b0ed35b45f9dca8c88555 Mon Sep 17 00:00:00 2001 From: Guilherme Iscaro Date: Sun, 14 Jul 2019 19:08:19 -0300 Subject: [PATCH] Properly set the border color when there are round borders on Android Drawing the border in one pass should only be done with the borderWidth and borderColor are the same for all directions (top, left, bottom and right), otherwise React may draw wrong colors. This commit adds a check to verify if all the colors are the same, otherwise it will draw each quadrilateral independently. --- .../views/view/ReactViewBackgroundDrawable.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 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 ed998e608018..f4b59e3551ea 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 @@ -338,6 +338,10 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) { } final RectF borderWidth = getDirectionAwareBorderInsets(); + int colorLeft = getBorderColor(Spacing.LEFT); + int colorTop = getBorderColor(Spacing.TOP); + int colorRight = getBorderColor(Spacing.RIGHT); + int colorBottom = getBorderColor(Spacing.BOTTOM); if (borderWidth.top > 0 || borderWidth.bottom > 0 @@ -346,12 +350,16 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) { // If it's a full and even border draw inner rect path with stroke final float fullBorderWidth = getFullBorderWidth(); + int borderColor = getBorderColor(Spacing.ALL); if (borderWidth.top == fullBorderWidth && borderWidth.bottom == fullBorderWidth && borderWidth.left == fullBorderWidth - && borderWidth.right == fullBorderWidth) { + && borderWidth.right == fullBorderWidth + && colorLeft == borderColor + && colorTop == borderColor + && colorRight == borderColor + && colorBottom == borderColor) { if (fullBorderWidth > 0) { - int borderColor = getBorderColor(Spacing.ALL); mPaint.setColor(ColorUtil.multiplyColorAlpha(borderColor, mAlpha)); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(fullBorderWidth); @@ -366,11 +374,6 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) { canvas.clipPath(mOuterClipPathForBorderRadius, Region.Op.INTERSECT); canvas.clipPath(mInnerClipPathForBorderRadius, Region.Op.DIFFERENCE); - int colorLeft = getBorderColor(Spacing.LEFT); - int colorTop = getBorderColor(Spacing.TOP); - int colorRight = getBorderColor(Spacing.RIGHT); - int colorBottom = getBorderColor(Spacing.BOTTOM); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { final boolean isRTL = getResolvedLayoutDirection() == View.LAYOUT_DIRECTION_RTL; int colorStart = getBorderColor(Spacing.START);