Skip to content

Commit ed3230c

Browse files
committed
moving logic to drawSide function
1 parent cbc9f45 commit ed3230c

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package com.facebook.react.views.view;
99

10+
import android.util.Log;
1011
import android.content.Context;
1112
import android.graphics.Canvas;
1213
import android.graphics.Color;
@@ -31,6 +32,7 @@
3132
import com.facebook.yoga.YogaConstants;
3233
import java.util.Arrays;
3334
import java.util.Locale;
35+
import java.lang.reflect.Method;
3436

3537
/**
3638
* A subclass of {@link Drawable} used for background of {@link ReactViewGroup}. It supports drawing
@@ -1110,41 +1112,29 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) {
11101112

11111113
mPaint.setColor(fastBorderColor);
11121114
mPaint.setStyle(Paint.Style.STROKE);
1113-
if (borderLeft > 0) {
1114-
mPathForSingleBorder.reset();
1115+
if (borderWidth.left > 0) {
11151116
int width = Math.round(borderWidth.left);
1116-
updatePathEffect(width);
1117-
mPaint.setStrokeWidth(width);
1118-
mPathForSingleBorder.moveTo(left, top - borderWidth.top/2);
1119-
mPathForSingleBorder.lineTo(left, bottom + borderWidth.bottom/2);
1120-
canvas.drawPath(mPathForSingleBorder, mPaint);
1117+
PointF start = new PointF(left, top - borderWidth.top/2);
1118+
PointF end = new PointF(left, bottom + borderWidth.bottom/2);
1119+
drawSide(width, start, end, canvas);
11211120
}
11221121
if (borderTop > 0) {
1123-
mPathForSingleBorder.reset();
11241122
int width = Math.round(borderWidth.top);
1125-
updatePathEffect(width);
1126-
mPaint.setStrokeWidth(width);
1127-
mPathForSingleBorder.moveTo(left, top);
1128-
mPathForSingleBorder.lineTo(right, top);
1129-
canvas.drawPath(mPathForSingleBorder, mPaint);
1123+
PointF start = new PointF(left, top);
1124+
PointF end = new PointF(right, top);
1125+
drawSide(width, start, end, canvas);
11301126
}
11311127
if (borderRight > 0) {
1132-
mPathForSingleBorder.reset();
11331128
int width = Math.round(borderWidth.right);
1134-
updatePathEffect(width);
1135-
mPaint.setStrokeWidth(width);
1136-
mPathForSingleBorder.moveTo(right, top - borderWidth.top/2);
1137-
mPathForSingleBorder.lineTo(right, bottom + borderWidth.bottom/2);
1138-
canvas.drawPath(mPathForSingleBorder, mPaint);
1129+
PointF start = new PointF(right, top - borderWidth.top/2);
1130+
PointF end = new PointF(right, bottom + borderWidth.bottom/2);
1131+
drawSide(width, start, end, canvas);
11391132
}
11401133
if (borderBottom > 0) {
1141-
mPathForSingleBorder.reset();
11421134
int width = Math.round(borderWidth.bottom);
1143-
updatePathEffect(width);
1144-
mPaint.setStrokeWidth(width);
1145-
mPathForSingleBorder.moveTo(left, bottom);
1146-
mPathForSingleBorder.lineTo(right, bottom);
1147-
canvas.drawPath(mPathForSingleBorder, mPaint);
1135+
PointF start = new PointF(left, bottom);
1136+
PointF end = new PointF(right, bottom);
1137+
drawSide(width, start, end, canvas);
11481138
}
11491139
}
11501140
} else {
@@ -1217,6 +1207,15 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) {
12171207
}
12181208
}
12191209

1210+
private void drawSide(int width, PointF start, PointF end, Canvas canvas) {
1211+
mPathForSingleBorder.reset();
1212+
updatePathEffect(width);
1213+
mPaint.setStrokeWidth(width);
1214+
mPathForSingleBorder.moveTo(start.x, start.y);
1215+
mPathForSingleBorder.lineTo(end.x, end.y);
1216+
canvas.drawPath(mPathForSingleBorder, mPaint);
1217+
}
1218+
12201219
private void drawQuadrilateral(
12211220
Canvas canvas,
12221221
int fillColor,

0 commit comments

Comments
 (0)