From 38a14ffc32dd66a31c80c702000288ee4065bde5 Mon Sep 17 00:00:00 2001 From: Alexander Blom Date: Mon, 22 Aug 2016 03:22:15 -0700 Subject: [PATCH] Make RN background drawable respect bounds Reviewed By: astreet Differential Revision: D3655395 fbshipit-source-id: c8c1b953337a3c5dfa0d905bc3d774db6b3f8271 --- .../view/ReactViewBackgroundDrawable.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 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 de9dcbc7fe8022..9b995cd5f403ab 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 @@ -359,6 +359,7 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) { // maybe draw borders? if (getBorderWidth(Spacing.LEFT) > 0 || getBorderWidth(Spacing.TOP) > 0 || getBorderWidth(Spacing.RIGHT) > 0 || getBorderWidth(Spacing.BOTTOM) > 0) { + Rect bounds = getBounds(); int borderLeft = getBorderWidth(Spacing.LEFT); int borderTop = getBorderWidth(Spacing.TOP); @@ -369,8 +370,10 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) { int colorRight = getBorderColor(Spacing.RIGHT); int colorBottom = getBorderColor(Spacing.BOTTOM); - int width = getBounds().width(); - int height = getBounds().height(); + int top = bounds.top; + int left = bounds.left; + int width = bounds.width(); + int height = bounds.height(); // If the path drawn previously is of the same color, // there would be a slight white space between borders @@ -387,44 +390,44 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) { if (borderLeft > 0 && colorLeft != Color.TRANSPARENT) { mPaint.setColor(colorLeft); mPathForBorder.reset(); - mPathForBorder.moveTo(0, 0); - mPathForBorder.lineTo(borderLeft, borderTop); - mPathForBorder.lineTo(borderLeft, height - borderBottom); - mPathForBorder.lineTo(0, height); - mPathForBorder.lineTo(0, 0); + mPathForBorder.moveTo(left, top); + mPathForBorder.lineTo(left + borderLeft, top + borderTop); + mPathForBorder.lineTo(left + borderLeft, top + height - borderBottom); + mPathForBorder.lineTo(left, top + height); + mPathForBorder.lineTo(left, top); canvas.drawPath(mPathForBorder, mPaint); } if (borderTop > 0 && colorTop != Color.TRANSPARENT) { mPaint.setColor(colorTop); mPathForBorder.reset(); - mPathForBorder.moveTo(0, 0); - mPathForBorder.lineTo(borderLeft, borderTop); - mPathForBorder.lineTo(width - borderRight, borderTop); - mPathForBorder.lineTo(width, 0); - mPathForBorder.lineTo(0, 0); + mPathForBorder.moveTo(left, top); + mPathForBorder.lineTo(left + borderLeft, top + borderTop); + mPathForBorder.lineTo(left + width - borderRight, top + borderTop); + mPathForBorder.lineTo(left + width, top); + mPathForBorder.lineTo(left, top); canvas.drawPath(mPathForBorder, mPaint); } if (borderRight > 0 && colorRight != Color.TRANSPARENT) { mPaint.setColor(colorRight); mPathForBorder.reset(); - mPathForBorder.moveTo(width, 0); - mPathForBorder.lineTo(width, height); - mPathForBorder.lineTo(width - borderRight, height - borderBottom); - mPathForBorder.lineTo(width - borderRight, borderTop); - mPathForBorder.lineTo(width, 0); + mPathForBorder.moveTo(left + width, top); + mPathForBorder.lineTo(left + width, top + height); + mPathForBorder.lineTo(left + width - borderRight, top + height - borderBottom); + mPathForBorder.lineTo(left + width - borderRight, top + borderTop); + mPathForBorder.lineTo(left + width, top); canvas.drawPath(mPathForBorder, mPaint); } if (borderBottom > 0 && colorBottom != Color.TRANSPARENT) { mPaint.setColor(colorBottom); mPathForBorder.reset(); - mPathForBorder.moveTo(0, height); - mPathForBorder.lineTo(width, height); - mPathForBorder.lineTo(width - borderRight, height - borderBottom); - mPathForBorder.lineTo(borderLeft, height - borderBottom); - mPathForBorder.lineTo(0, height); + mPathForBorder.moveTo(left, top + height); + mPathForBorder.lineTo(left + width, top + height); + mPathForBorder.lineTo(left + width - borderRight, top + height - borderBottom); + mPathForBorder.lineTo(left + borderLeft, top + height - borderBottom); + mPathForBorder.lineTo(left, top + height); canvas.drawPath(mPathForBorder, mPaint); }