Skip to content

Commit 0a93b32

Browse files
author
Andrew Paramoshkin
committed
update: Change objects to StyleSheets. Update README. Clear state variables.
1 parent 57c1fcf commit 0a93b32

File tree

3 files changed

+39
-38
lines changed

3 files changed

+39
-38
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ Circle-style checkbox component for React Native.
2323

2424
## Available properties:
2525

26-
- `checked` : initial state of checkbox. Default: `false`
27-
- `onPress` : function that will be invoked by pressing to checkbox with checked property as argument.
28-
- `outerSize` : Diameter of outer circle. Minimum: `10`, default: `26`
29-
- `filterSize` : Diameter of underlayer circle. Minimum: `7`, default: `23`
30-
- `innerSize` : Diameter of flag. Minimum: `2`, default: `18`
31-
- `outerColor` : Color of outer circle. Default: `#FC9527`
32-
- `filterColor` : Color of underlayer circle. Default: `#FFF`
33-
- `innerColor` : Color of flag. Default: `#FC9527`
26+
Name | Default | Type | Required | Description
27+
:--- | :----- | :- | :-- | :--------------
28+
checked | false | boolean | - | Initial state of checkbox
29+
onPress | null | Func | * | Function that will be invoked by pressing to checkbox with checked property as argument
30+
outerSize | 26 | number | - | Outer circle diameter. Min: 10
31+
filterSize | 23 | number | - | Underlayer circle diameter. Min: 7
32+
innerSize | 18 | number | - | Flag circle diameter. Min: 2
33+
outerColor | #FC9527 | string | - | Outer circle color
34+
filterColor | #FFF | string | - | Underlayer circle color
35+
innerColor | #FC9527 | string | - | Flag circle color

index.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
ReactNativeCircleCheckbox 0.1.1
2+
ReactNativeCircleCheckbox 0.1.2
33
https://github.com/ParamoshkinAndrew/ReactNativeCircleCheckbox
44
(c) 2016 Andrew Paramoshkin <paramoshkin.andrew@gmail.com>
55
ReactNativeCircleCheckbox may be freely distributed under the MIT license.
@@ -41,40 +41,39 @@ class CircleCheckBox extends Component {
4141
constructor(props) {
4242
super(props);
4343
var outerSize = (parseInt(props.outerSize) < 10 || isNaN(parseInt(props.outerSize))) ? 10 : parseInt(props.outerSize);
44-
var outerStyle = {
45-
width: outerSize,
46-
height: outerSize,
47-
borderRadius: outerSize/2,
48-
backgroundColor: props.outerColor
49-
};
50-
var filterSize = (parseInt(props.filterSize) > outerStyle.width + 3 || isNaN(parseInt(props.filterSize))) ? outerStyle.width - 3 : parseInt(props.filterSize);
51-
var filterStyle = {
52-
width: filterSize,
53-
height: filterSize,
54-
borderRadius: filterSize/2,
55-
backgroundColor: props.filterColor
56-
};
57-
var innerSize = (parseInt(props.innerSize) > filterStyle.width + 5 || isNaN(parseInt(props.innerSize))) ? filterStyle.width - 5 : parseInt(props.innerSize);
58-
var innerStyle = {
59-
width: innerSize,
60-
height: innerSize,
61-
borderRadius: innerSize/2,
62-
backgroundColor: props.innerColor
63-
};
44+
var filterSize = (parseInt(props.filterSize) > outerSize + 3 || isNaN(parseInt(props.filterSize))) ? outerSize - 3 : parseInt(props.filterSize);
45+
var innerSize = (parseInt(props.innerSize) > filterSize + 5 || isNaN(parseInt(props.innerSize))) ? filterSize - 5 : parseInt(props.innerSize);
46+
47+
var customStyle = StyleSheet.create({
48+
_circleOuterStyle: {
49+
width: outerSize,
50+
height: outerSize,
51+
borderRadius: outerSize/2,
52+
backgroundColor: props.outerColor
53+
},
54+
_circleFilterStyle: {
55+
width: filterSize,
56+
height: filterSize,
57+
borderRadius: filterSize/2,
58+
backgroundColor: props.filterColor
59+
},
60+
_circleInnerStyle: {
61+
width: innerSize,
62+
height: innerSize,
63+
borderRadius: innerSize/2,
64+
backgroundColor: props.innerColor
65+
}
66+
});
6467

6568
this.state = {
66-
checked: props.checked,
67-
onToggle: props.onToggle,
68-
_circleOuterStyle: outerStyle,
69-
_circleFilterStyle: filterStyle,
70-
_circleInnerStyle: innerStyle
69+
customStyle: customStyle
7170
}
7271
}
7372

7473
render() {
7574
return (
76-
<TouchableHighlight style={[styles.alignStyle, this.state._circleOuterStyle]} onPress={() => this._onToggle()}>
77-
<View style={[styles.alignStyle, this.state._circleFilterStyle]}>
75+
<TouchableHighlight style={[styles.alignStyle, this.state.customStyle._circleOuterStyle]} onPress={this._onToggle.bind(this)}>
76+
<View style={[styles.alignStyle, this.state.customStyle._circleFilterStyle]}>
7877
{this._renderInner()}
7978
</View>
8079
</TouchableHighlight>
@@ -88,7 +87,7 @@ class CircleCheckBox extends Component {
8887
}
8988

9089
_renderInner() {
91-
return this.props.checked ? (<View style={this.state._circleInnerStyle} />) : (<View/>);
90+
return this.props.checked ? (<View style={this.state.customStyle._circleInnerStyle} />) : (<View/>);
9291
}
9392
}
9493

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-circle-checkbox",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Circle checkbox component for React Native",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)