Skip to content

Commit 44ea7fa

Browse files
author
Andrew Paramoshkin
committed
add: Main file
1 parent df69d41 commit 44ea7fa

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

index.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
ReactNativeCircleCheckbox 0.1.0
3+
https://github.com/ParamoshkinAndrew/ReactNativeCircleCheckbox
4+
(c) 2016 Andrew Paramoshkin <paramoshkin.andrew@gmail.com>
5+
ReactNativeCircleCheckbox may be freely distributed under the MIT license.
6+
*/
7+
8+
'use strict'
9+
10+
var React = require('react-native');
11+
var {
12+
StyleSheet,
13+
View,
14+
Component,
15+
TouchableHighlight
16+
} = React;
17+
18+
class CircleCheckBox extends Component {
19+
20+
constructor(props) {
21+
super(props);
22+
var outerSize = (props.outerSize) ? props.outerSize : 26;
23+
outerSize = (parseInt(outerSize) < 10 || isNaN(parseInt(outerSize))) ? 10 : parseInt(outerSize);
24+
var outerColor = (props.outerColor) ? props.outerColor : '#FC9527';
25+
var outerStyle = {
26+
width: outerSize,
27+
height: outerSize,
28+
borderRadius: outerSize/2,
29+
backgroundColor: outerColor
30+
};
31+
var filterSize = (parseInt(props.filterSize) > outerStyle.width + 3 || isNaN(parseInt(props.filterSize))) ? outerStyle.width - 3 : parseInt(props.filterSize);
32+
var filterColor = (props.filterColor) ? props.filterColor : '#FFF';
33+
var filterStyle = {
34+
width: filterSize,
35+
height: filterSize,
36+
borderRadius: filterSize/2,
37+
backgroundColor: filterColor
38+
};
39+
var innerSize = (parseInt(props.innerSize) > filterStyle.width + 5 || isNaN(parseInt(props.innerSize))) ? filterStyle.width - 5 : parseInt(props.innerSize);
40+
var innerColor = (props.innerColor) ? props.innerColor : '#FC9527';
41+
var innerStyle = {
42+
width: innerSize,
43+
height: innerSize,
44+
borderRadius: innerSize/2,
45+
backgroundColor: innerColor
46+
};
47+
48+
this.state = {
49+
checked: props.checked ? props.checked : false,
50+
onPress: props.onPress,
51+
_circleOuterStyle: outerStyle,
52+
_circleFilterStyle: filterStyle,
53+
_circleInnerStyle: innerStyle
54+
}
55+
}
56+
57+
render() {
58+
return (
59+
<TouchableHighlight style={[styles.alignStyle, this.state._circleOuterStyle]}
60+
onPress={ () =>
61+
(this.state.onPress) ?
62+
this.state.onPress(this.state.checked) :
63+
this._onPress(this.state.checked) }
64+
>
65+
<View style={[styles.alignStyle, this.state._circleFilterStyle]}>
66+
{this._renderInner()}
67+
</View>
68+
</TouchableHighlight>
69+
);
70+
}
71+
72+
_onPress(checked) {
73+
this.setState({
74+
checked: !checked
75+
});
76+
}
77+
78+
_renderInner() {
79+
return this.state.checked ? (<View style={this.state._circleInnerStyle} />) : (<View/>);
80+
}
81+
}
82+
83+
var styles = StyleSheet.create({
84+
alignStyle: {
85+
justifyContent: 'center',
86+
alignItems: 'center'
87+
},
88+
});
89+
90+
module.exports = CircleCheckBox;

package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "react-native-circle-checkbox",
3+
"version": "0.1.0",
4+
"description": "Circle checkbox component for React Native",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/ParamoshkinAndrew/ReactNativeCircleCheckbox.git"
12+
},
13+
"keywords": [
14+
"react",
15+
"react",
16+
"native",
17+
"facebook",
18+
"component",
19+
"checkbox",
20+
"ios"
21+
],
22+
"author": "Andrew Paramoshkin <paramoshkin.andrew@gmail.com>",
23+
"licenses": [
24+
{
25+
"type" :"MIT",
26+
"url": "https://github.com/ParamoshkinAndrew/ReactNativeCircleCheckbox/blob/master/LICENSE"
27+
}
28+
],
29+
"bugs": {
30+
"url": "https://github.com/ParamoshkinAndrew/ReactNativeCircleCheckbox/issues"
31+
},
32+
"homepage": "https://github.com/ParamoshkinAndrew/ReactNativeCircleCheckbox"
33+
}

0 commit comments

Comments
 (0)