|
@@ -0,0 +1,71 @@
|
|
1
|
+package com.reactnativenavigation.views;
|
|
2
|
+
|
|
3
|
+import android.graphics.Canvas;
|
|
4
|
+import android.graphics.Color;
|
|
5
|
+import android.graphics.Paint;
|
|
6
|
+import android.graphics.Path;
|
|
7
|
+import android.graphics.Point;
|
|
8
|
+import android.graphics.drawable.ShapeDrawable;
|
|
9
|
+import android.graphics.drawable.shapes.RectShape;
|
|
10
|
+import android.graphics.drawable.shapes.Shape;
|
|
11
|
+
|
|
12
|
+import com.reactnativenavigation.params.StyleParams;
|
|
13
|
+
|
|
14
|
+class TopBarBorder extends ShapeDrawable {
|
|
15
|
+ private StyleParams.Color backgroundColor;
|
|
16
|
+ private final Paint pathPaint;
|
|
17
|
+ private Border border;
|
|
18
|
+
|
|
19
|
+ private class Border {
|
|
20
|
+ private Path path;
|
|
21
|
+ int width;
|
|
22
|
+ int height;
|
|
23
|
+
|
|
24
|
+ Border(int width, int height) {
|
|
25
|
+ this.width = width;
|
|
26
|
+ this.height = height;
|
|
27
|
+ path = createPath();
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ private Path createPath() {
|
|
31
|
+ Point a = new Point(0, height);
|
|
32
|
+ Point b = new Point(width, height);
|
|
33
|
+ Path path = new Path();
|
|
34
|
+ path.moveTo(a.x, a.y);
|
|
35
|
+ path.lineTo(b.x, b.y);
|
|
36
|
+ return path;
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ boolean dimensionsChanged(int width, int height) {
|
|
40
|
+ return this.width != width || this.height != height;
|
|
41
|
+ }
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ TopBarBorder(StyleParams styleParams) {
|
|
45
|
+ super(new RectShape());
|
|
46
|
+ backgroundColor = styleParams.topBarColor;
|
|
47
|
+ pathPaint = createPathPaint(styleParams.topBarBorderColor, styleParams.topBarBorderWidth);
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ private Paint createPathPaint(StyleParams.Color color, float strokeWidth) {
|
|
51
|
+ Paint res = new Paint();
|
|
52
|
+ res.setStyle(Paint.Style.STROKE);
|
|
53
|
+ res.setColor(color.getColor());
|
|
54
|
+ res.setStrokeWidth(strokeWidth);
|
|
55
|
+ return res;
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ @Override
|
|
59
|
+ protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
|
|
60
|
+ super.onDraw(shape, canvas, paint);
|
|
61
|
+ createBorder(canvas);
|
|
62
|
+ paint.setColor(backgroundColor.getColor(Color.WHITE));
|
|
63
|
+ canvas.drawPath(border.path, pathPaint);
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ private void createBorder(Canvas canvas) {
|
|
67
|
+ if (border == null || border.dimensionsChanged(canvas.getWidth(), canvas.getHeight())) {
|
|
68
|
+ border = new Border(canvas.getWidth(), canvas.getHeight());
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+}
|