-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircle.js
62 lines (58 loc) · 1.49 KB
/
Circle.js
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
62
import React, { Component } from "react";
import { StyleSheet, View } from "react-native";
import PropTypes from "prop-types";
const styles = StyleSheet.create({
container: {
position: "absolute"
}
});
export default class Circle extends Component {
static defaultProps = {
isFill: false,
backgroundColor: "transparent"
};
// 构造
constructor(props) {
super(props);
// 初始状态
this.state = {};
this._diameter = props.radius * 2;
}
render() {
return (
<View
accessibilityLabel={this.props.accessibilityLabel}
style={[
styles.container,
this.props.isFill
? { backgroundColor: this.props.color }
: {
borderColor: this.props.color,
borderWidth: this.props.borderWidth,
backgroundColor: this.props.backgroundColor
},
{
width: this._diameter,
height: this._diameter,
borderRadius: this.props.radius,
left: this.props.position.left,
top: this.props.position.top
}
]}
>
{this.props.children}
</View>
);
}
}
Circle.propTypes = {
isFill: PropTypes.bool,
color: PropTypes.string.isRequired,
radius: PropTypes.number.isRequired,
borderWidth: PropTypes.number.isRequired,
backgroundColor: PropTypes.string,
position: PropTypes.shape({
left: PropTypes.number.isRequired,
top: PropTypes.number.isRequired
}).isRequired
};