-
Notifications
You must be signed in to change notification settings - Fork 1
/
Circle.js
74 lines (65 loc) · 2.05 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
63
64
65
66
67
68
69
70
71
72
73
74
import React, {
Component,
} from 'react'
import PropTypes from 'prop-types'
import {
StyleSheet,
View,
} from 'react-native'
const styles = StyleSheet.create({
container: {
position: 'absolute',
}
})
//const borderWidth = 1
export default class Circle extends Component {
static defaultProps = {
isFill: false,
backgroundColor: 'transparent',
}
static 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,
}
// 构造
constructor(props) {
super(props)
// 初始状态
this.state = {}
this._diameter = props.radius * 2
}
render() {
return (
<View
//onLayout={ (e) => {
// //console.log('this._diameter = ' + this._diameter)
// //console.log('e.nativeEvent')
// //console.log(e.nativeEvent)
//}}
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 - borderWidth,
//top: this.props.position.top - borderWidth,
left: this.props.position.left,
top: this.props.position.top,
}
]}>
{this.props.children}
</View>
)
}
}