Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -1092,28 +1101,50 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) {
colorTop,
colorRight,
colorBottom);

if (fastBorderColor != 0) {
if (Color.alpha(fastBorderColor) != 0) {
// Border color is not transparent.
int right = bounds.right;
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 {
Expand Down
9 changes: 6 additions & 3 deletions packages/rn-tester/js/examples/Border/BorderExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const styles = StyleSheet.create({
border1: {
borderWidth: 10,
borderColor: 'brown',
borderStyle: 'dotted',
},
borderRadius: {
borderWidth: 10,
Expand All @@ -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,
Expand Down Expand Up @@ -99,12 +100,14 @@ const styles = StyleSheet.create({
},
border8Left: {
borderLeftWidth: 5,
borderStyle: 'dotted',
},
border8Bottom: {
borderBottomWidth: 5,
},
border8Right: {
borderRightWidth: 5,
borderStyle: 'dashed',
},
border9: {
borderWidth: 10,
Expand Down