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 18b8d6b6845403..48ce45906b989b 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 @@ -90,6 +90,7 @@ private enum BorderStyle { private @Nullable Path mOuterClipPathForBorderRadius; private @Nullable Path mPathForBorderRadiusOutline; private @Nullable Path mPathForBorder; + private Path mPathForSingleBorder = new Path(); private @Nullable Path mCenterDrawPath; private @Nullable RectF mInnerClipTempRectForBorderRadius; private @Nullable RectF mOuterClipTempRectForBorderRadius; @@ -975,6 +976,14 @@ private void updatePathEffect() { mPaint.setPathEffect(mPathEffectForBorderStyle); } + private void updatePathEffect(int borderWidth) { + PathEffect pathEffectForBorderStyle = null; + if(mBorderStyle != null) { + pathEffectForBorderStyle = BorderStyle.getPathEffect(mBorderStyle, borderWidth); + } + mPaint.setPathEffect(pathEffectForBorderStyle); + } + /** For rounded borders we use default "borderWidth" property. */ public float getFullBorderWidth() { return (mBorderWidth != null && !YogaConstants.isUndefined(mBorderWidth.getRaw(Spacing.ALL))) @@ -1092,6 +1101,7 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) { colorTop, colorRight, colorBottom); + if (fastBorderColor != 0) { if (Color.alpha(fastBorderColor) != 0) { // Border color is not transparent. @@ -1099,21 +1109,42 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) { int bottom = bounds.bottom; mPaint.setColor(fastBorderColor); + mPaint.setStyle(Paint.Style.STROKE); if (borderLeft > 0) { - int leftInset = left + borderLeft; - canvas.drawRect(left, top, leftInset, bottom - borderBottom, mPaint); + mPathForSingleBorder.reset(); + int width = Math.round(borderWidth.left); + updatePathEffect(width); + mPaint.setStrokeWidth(width); + mPathForSingleBorder.moveTo(left, top - borderWidth.top/2); + mPathForSingleBorder.lineTo(left, bottom + borderWidth.bottom/2); + canvas.drawPath(mPathForSingleBorder, mPaint); } if (borderTop > 0) { - int topInset = top + borderTop; - canvas.drawRect(left + borderLeft, top, right, topInset, mPaint); + mPathForSingleBorder.reset(); + int width = Math.round(borderWidth.top); + updatePathEffect(width); + mPaint.setStrokeWidth(width); + mPathForSingleBorder.moveTo(left, top); + mPathForSingleBorder.lineTo(right, top); + canvas.drawPath(mPathForSingleBorder, mPaint); } if (borderRight > 0) { - int rightInset = right - borderRight; - canvas.drawRect(rightInset, top + borderTop, right, bottom, mPaint); + mPathForSingleBorder.reset(); + int width = Math.round(borderWidth.right); + updatePathEffect(width); + mPaint.setStrokeWidth(width); + mPathForSingleBorder.moveTo(right, top - borderWidth.top/2); + mPathForSingleBorder.lineTo(right, bottom + borderWidth.bottom/2); + canvas.drawPath(mPathForSingleBorder, mPaint); } if (borderBottom > 0) { - int bottomInset = bottom - borderBottom; - canvas.drawRect(left, bottomInset, right - borderRight, bottom, mPaint); + mPathForSingleBorder.reset(); + int width = Math.round(borderWidth.bottom); + updatePathEffect(width); + mPaint.setStrokeWidth(width); + mPathForSingleBorder.moveTo(left, bottom); + mPathForSingleBorder.lineTo(right, bottom); + canvas.drawPath(mPathForSingleBorder, mPaint); } } } else { diff --git a/packages/rn-tester/js/examples/Border/BorderExample.js b/packages/rn-tester/js/examples/Border/BorderExample.js index f43016ef60ed45..083361c8c208fc 100644 --- a/packages/rn-tester/js/examples/Border/BorderExample.js +++ b/packages/rn-tester/js/examples/Border/BorderExample.js @@ -23,6 +23,7 @@ const styles = StyleSheet.create({ border1: { borderWidth: 10, borderColor: 'brown', + borderStyle: 'dotted', }, borderRadius: { borderWidth: 10, @@ -38,10 +39,10 @@ const styles = StyleSheet.create({ }, border3: { borderColor: 'purple', - borderTopWidth: 10, + borderTopWidth: 7, borderRightWidth: 20, - borderBottomWidth: 30, - borderLeftWidth: 40, + borderBottomWidth: 10, + borderLeftWidth: 5, }, border4: { borderTopWidth: 10, @@ -99,12 +100,14 @@ const styles = StyleSheet.create({ }, border8Left: { borderLeftWidth: 5, + borderStyle: 'dotted', }, border8Bottom: { borderBottomWidth: 5, }, border8Right: { borderRightWidth: 5, + borderStyle: 'dashed', }, border9: { borderWidth: 10,