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
0 commit comments