-
Notifications
You must be signed in to change notification settings - Fork 31
/
Point.js
76 lines (66 loc) · 2.2 KB
/
Point.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React, {
PropTypes,
Component,
} from 'react'
import {
StyleSheet,
View,
} from 'react-native'
import Circle from './Circle'
export default class Point extends Component {
static defaultProps = {
isActive: false,
isWarning: false,
}
static propTypes = {
index: PropTypes.number.isRequired,
radius: PropTypes.number.isRequired,
borderWidth: PropTypes.number.isRequired,
isActive: PropTypes.bool.isRequired,
isWarning: PropTypes.bool.isRequired,
backgroundColor: PropTypes.string,
color: PropTypes.string.isRequired,
activeColor: PropTypes.string.isRequired,
warningColor: PropTypes.string.isRequired,
position: PropTypes.shape({
left: PropTypes.number.isRequired,
top: PropTypes.number.isRequired,
}).isRequired,
}
// 构造
constructor (props) {
super(props)
// 初始状态
this.state = {}
this._outerCircleRadius = props.radius
this._outerCirclePosition = props.position
this._innerCircleRadius = this._outerCircleRadius / 3
this._innerCirclePosition = {
left: this._innerCircleRadius * 2 - props.borderWidth,
top: this._innerCircleRadius * 2 - props.borderWidth,
}
}
render () {
this._color = this.props.isWarning ?
this.props.warningColor :
( this.props.isActive ? this.props.activeColor : this.props.color )
return (
<Circle
backgroundColor={this.props.backgroundColor}
color={this._color}
radius={this.props.radius}
borderWidth={this.props.borderWidth}
position={this._outerCirclePosition}>
{ (this.props.isActive || this.props.isWarning) ? (
<Circle
isFill={true}
color={this._color}
radius={this._innerCircleRadius}
borderWidth={this.props.borderWidth}
position={this._innerCirclePosition}
/>
) : null}
</Circle>
)
}
}