-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
CircleView.java
61 lines (48 loc) · 1.47 KB
/
CircleView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright (c) 2015-present, Horcrux.
* All rights reserved.
*
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
package versioned.host.exp.exponent.modules.api.components.svg;
import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;
@SuppressLint("ViewConstructor")
class CircleView extends RenderableView {
private SVGLength mCx;
private SVGLength mCy;
private SVGLength mR;
public CircleView(ReactContext reactContext) {
super(reactContext);
}
@ReactProp(name = "cx")
public void setCx(Dynamic cx) {
mCx = SVGLength.from(cx);
invalidate();
}
@ReactProp(name = "cy")
public void setCy(Dynamic cy) {
mCy = SVGLength.from(cy);
invalidate();
}
@ReactProp(name = "r")
public void setR(Dynamic r) {
mR = SVGLength.from(r);
invalidate();
}
@Override
Path getPath(Canvas canvas, Paint paint) {
Path path = new Path();
double cx = relativeOnWidth(mCx);
double cy = relativeOnHeight(mCy);
double r = relativeOnOther(mR);
path.addCircle((float) cx, (float) cy, (float) r, Path.Direction.CW);
return path;
}
}