Make RN background drawable respect bounds

Reviewed By: astreet

Differential Revision: D3655395

fbshipit-source-id: c8c1b953337a3c5dfa0d905bc3d774db6b3f8271
This commit is contained in:
Alexander Blom 2016-08-22 03:22:15 -07:00 committed by Facebook Github Bot
parent 1b6e67e991
commit 38a14ffc32
1 changed files with 25 additions and 22 deletions

View File

@ -359,6 +359,7 @@ import com.facebook.csslayout.Spacing;
// 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 @@ import com.facebook.csslayout.Spacing;
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 @@ import com.facebook.csslayout.Spacing;
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);
}