Revert D7569885: Fix anti aliasing rounded background

Differential Revision:
D7569885

Original commit changeset: 4bfb00485211

fbshipit-source-id: 2fc76ca8615d5562ebe8c7527e9a54058b8d82dc
This commit is contained in:
Andrew Chen (Eng) 2018-04-17 10:13:52 -07:00 committed by Facebook Github Bot
parent 1433d15557
commit e4f88c66e3
1 changed files with 84 additions and 103 deletions

View File

@ -343,132 +343,113 @@ public class ReactViewBackgroundDrawable extends Drawable {
|| borderWidth.bottom > 0 || borderWidth.bottom > 0
|| borderWidth.left > 0 || borderWidth.left > 0
|| borderWidth.right > 0) { || borderWidth.right > 0) {
mPaint.setStyle(Paint.Style.FILL);
//If it's a full and even border draw inner rect path with stroke // Draw border
final float fullBorderWidth = getFullBorderWidth(); canvas.clipPath(mOuterClipPathForBorderRadius, Region.Op.INTERSECT);
if (borderWidth.top == fullBorderWidth && canvas.clipPath(mInnerClipPathForBorderRadius, Region.Op.DIFFERENCE);
borderWidth.bottom == fullBorderWidth &&
borderWidth.left == fullBorderWidth &&
borderWidth.right == fullBorderWidth) {
if (fullBorderWidth > 0) {
int borderColor = getBorderColor(Spacing.ALL);
mPaint.setColor(ColorUtil.multiplyColorAlpha(borderColor, mAlpha));
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(fullBorderWidth);
canvas.drawPath(mInnerClipPathForBorderRadius, mPaint);
}
}
//In the case of uneven border widths/colors draw quadrilateral in each direction
else {
mPaint.setStyle(Paint.Style.FILL);
// Draw border int colorLeft = getBorderColor(Spacing.LEFT);
canvas.clipPath(mOuterClipPathForBorderRadius, Region.Op.INTERSECT); int colorTop = getBorderColor(Spacing.TOP);
canvas.clipPath(mInnerClipPathForBorderRadius, Region.Op.DIFFERENCE); int colorRight = getBorderColor(Spacing.RIGHT);
int colorBottom = getBorderColor(Spacing.BOTTOM);
int colorLeft = getBorderColor(Spacing.LEFT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
int colorTop = getBorderColor(Spacing.TOP); final boolean isRTL = getResolvedLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
int colorRight = getBorderColor(Spacing.RIGHT); int colorStart = getBorderColor(Spacing.START);
int colorBottom = getBorderColor(Spacing.BOTTOM); int colorEnd = getBorderColor(Spacing.END);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(mContext)) {
final boolean isRTL = getResolvedLayoutDirection() == View.LAYOUT_DIRECTION_RTL; if (!isBorderColorDefined(Spacing.START)) {
int colorStart = getBorderColor(Spacing.START); colorStart = colorLeft;
int colorEnd = getBorderColor(Spacing.END); }
if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(mContext)) { if (!isBorderColorDefined(Spacing.END)) {
if (!isBorderColorDefined(Spacing.START)) { colorEnd = colorRight;
colorStart = colorLeft; }
}
if (!isBorderColorDefined(Spacing.END)) { final int directionAwareColorLeft = isRTL ? colorEnd : colorStart;
colorEnd = colorRight; final int directionAwareColorRight = isRTL ? colorStart : colorEnd;
}
final int directionAwareColorLeft = isRTL ? colorEnd : colorStart; colorLeft = directionAwareColorLeft;
final int directionAwareColorRight = isRTL ? colorStart : colorEnd; colorRight = directionAwareColorRight;
} else {
final int directionAwareColorLeft = isRTL ? colorEnd : colorStart;
final int directionAwareColorRight = isRTL ? colorStart : colorEnd;
final boolean isColorStartDefined = isBorderColorDefined(Spacing.START);
final boolean isColorEndDefined = isBorderColorDefined(Spacing.END);
final boolean isDirectionAwareColorLeftDefined = isRTL ? isColorEndDefined : isColorStartDefined;
final boolean isDirectionAwareColorRightDefined = isRTL ? isColorStartDefined : isColorEndDefined;
if (isDirectionAwareColorLeftDefined) {
colorLeft = directionAwareColorLeft; colorLeft = directionAwareColorLeft;
}
if (isDirectionAwareColorRightDefined) {
colorRight = directionAwareColorRight; colorRight = directionAwareColorRight;
} else {
final int directionAwareColorLeft = isRTL ? colorEnd : colorStart;
final int directionAwareColorRight = isRTL ? colorStart : colorEnd;
final boolean isColorStartDefined = isBorderColorDefined(Spacing.START);
final boolean isColorEndDefined = isBorderColorDefined(Spacing.END);
final boolean isDirectionAwareColorLeftDefined =
isRTL ? isColorEndDefined : isColorStartDefined;
final boolean isDirectionAwareColorRightDefined =
isRTL ? isColorStartDefined : isColorEndDefined;
if (isDirectionAwareColorLeftDefined) {
colorLeft = directionAwareColorLeft;
}
if (isDirectionAwareColorRightDefined) {
colorRight = directionAwareColorRight;
}
} }
} }
}
final float left = mOuterClipTempRectForBorderRadius.left; final float left = mOuterClipTempRectForBorderRadius.left;
final float right = mOuterClipTempRectForBorderRadius.right; final float right = mOuterClipTempRectForBorderRadius.right;
final float top = mOuterClipTempRectForBorderRadius.top; final float top = mOuterClipTempRectForBorderRadius.top;
final float bottom = mOuterClipTempRectForBorderRadius.bottom; final float bottom = mOuterClipTempRectForBorderRadius.bottom;
if (borderWidth.left > 0) { if (borderWidth.left > 0) {
final float x1 = left; final float x1 = left;
final float y1 = top; final float y1 = top;
final float x2 = mInnerTopLeftCorner.x; final float x2 = mInnerTopLeftCorner.x;
final float y2 = mInnerTopLeftCorner.y; final float y2 = mInnerTopLeftCorner.y;
final float x3 = mInnerBottomLeftCorner.x; final float x3 = mInnerBottomLeftCorner.x;
final float y3 = mInnerBottomLeftCorner.y; final float y3 = mInnerBottomLeftCorner.y;
final float x4 = left; final float x4 = left;
final float y4 = bottom; final float y4 = bottom;
drawQuadrilateral(canvas, colorLeft, x1, y1, x2, y2, x3, y3, x4, y4); drawQuadrilateral(canvas, colorLeft, x1, y1, x2, y2, x3, y3, x4, y4);
} }
if (borderWidth.top > 0) { if (borderWidth.top > 0) {
final float x1 = left; final float x1 = left;
final float y1 = top; final float y1 = top;
final float x2 = mInnerTopLeftCorner.x; final float x2 = mInnerTopLeftCorner.x;
final float y2 = mInnerTopLeftCorner.y; final float y2 = mInnerTopLeftCorner.y;
final float x3 = mInnerTopRightCorner.x; final float x3 = mInnerTopRightCorner.x;
final float y3 = mInnerTopRightCorner.y; final float y3 = mInnerTopRightCorner.y;
final float x4 = right; final float x4 = right;
final float y4 = top; final float y4 = top;
drawQuadrilateral(canvas, colorTop, x1, y1, x2, y2, x3, y3, x4, y4); drawQuadrilateral(canvas, colorTop, x1, y1, x2, y2, x3, y3, x4, y4);
} }
if (borderWidth.right > 0) { if (borderWidth.right > 0) {
final float x1 = right; final float x1 = right;
final float y1 = top; final float y1 = top;
final float x2 = mInnerTopRightCorner.x; final float x2 = mInnerTopRightCorner.x;
final float y2 = mInnerTopRightCorner.y; final float y2 = mInnerTopRightCorner.y;
final float x3 = mInnerBottomRightCorner.x; final float x3 = mInnerBottomRightCorner.x;
final float y3 = mInnerBottomRightCorner.y; final float y3 = mInnerBottomRightCorner.y;
final float x4 = right; final float x4 = right;
final float y4 = bottom; final float y4 = bottom;
drawQuadrilateral(canvas, colorRight, x1, y1, x2, y2, x3, y3, x4, y4); drawQuadrilateral(canvas, colorRight, x1, y1, x2, y2, x3, y3, x4, y4);
} }
if (borderWidth.bottom > 0) { if (borderWidth.bottom > 0) {
final float x1 = left; final float x1 = left;
final float y1 = bottom; final float y1 = bottom;
final float x2 = mInnerBottomLeftCorner.x; final float x2 = mInnerBottomLeftCorner.x;
final float y2 = mInnerBottomLeftCorner.y; final float y2 = mInnerBottomLeftCorner.y;
final float x3 = mInnerBottomRightCorner.x; final float x3 = mInnerBottomRightCorner.x;
final float y3 = mInnerBottomRightCorner.y; final float y3 = mInnerBottomRightCorner.y;
final float x4 = right; final float x4 = right;
final float y4 = bottom; final float y4 = bottom;
drawQuadrilateral(canvas, colorBottom, x1, y1, x2, y2, x3, y3, x4, y4); drawQuadrilateral(canvas, colorBottom, x1, y1, x2, y2, x3, y3, x4, y4);
}
} }
} }
canvas.restore(); canvas.restore();
} }