Skip to content

Commit

Permalink
Make RN background drawable respect bounds
Browse files Browse the repository at this point in the history
Reviewed By: astreet

Differential Revision: D3655395

fbshipit-source-id: c8c1b953337a3c5dfa0d905bc3d774db6b3f8271
  • Loading branch information
lexs authored and Facebook Github Bot committed Aug 22, 2016
1 parent 1b6e67e commit 38a14ff
Showing 1 changed file with 25 additions and 22 deletions.
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
}

Expand Down

0 comments on commit 38a14ff

Please sign in to comment.