1- /**
1+ /**
22 * react-native-check-box
33 * Checkbox component for react native, it works on iOS and Android
44 * https://github.com/crazycodeboy/react-native-check-box
@@ -20,6 +20,12 @@ import PropTypes from 'prop-types';
2020
2121
2222export default class CheckBox extends Component {
23+ constructor ( props ) {
24+ super ( props ) ;
25+ this . state = {
26+ isChecked : this . props . isChecked ,
27+ }
28+ }
2329 static propTypes = {
2430 ...( ViewPropTypes || View . PropTypes ) ,
2531 leftText : PropTypes . string ,
@@ -42,7 +48,12 @@ export default class CheckBox extends Component {
4248 leftTextStyle : { } ,
4349 rightTextStyle : { }
4450 }
45-
51+ onClick ( ) {
52+ this . setState ( {
53+ isChecked : ! this . state . isChecked
54+ } )
55+ this . props . onClick ( ) ;
56+ }
4657 _renderLeft ( ) {
4758 if ( this . props . leftTextView ) return this . props . leftTextView ;
4859 if ( ! this . props . leftText ) return null ;
@@ -62,7 +73,7 @@ export default class CheckBox extends Component {
6273 if ( this . props . isIndeterminate ) {
6374 return this . props . indeterminateImage ? this . props . indeterminateImage : this . genCheckedImage ( ) ;
6475 }
65- if ( this . props . isChecked ) {
76+ if ( this . state . isChecked ) {
6677 return this . props . checkedImage ? this . props . checkedImage : this . genCheckedImage ( ) ;
6778 } else {
6879 return this . props . unCheckedImage ? this . props . unCheckedImage : this . genCheckedImage ( ) ;
@@ -72,10 +83,10 @@ export default class CheckBox extends Component {
7283 genCheckedImage ( ) {
7384 var source ;
7485 if ( this . props . isIndeterminate ) {
75- source = require ( './img/ic_indeterminate_check_box.png' ) ;
86+ source = require ( './img/ic_indeterminate_check_box.png' ) ;
7687 }
7788 else {
78- source = this . props . isChecked ? require ( './img/ic_check_box.png' ) : require ( './img/ic_check_box_outline_blank.png' ) ;
89+ source = this . state . isChecked ? require ( './img/ic_check_box.png' ) : require ( './img/ic_check_box_outline_blank.png' ) ;
7990 }
8091
8192 return (
@@ -87,7 +98,7 @@ export default class CheckBox extends Component {
8798 return (
8899 < TouchableHighlight
89100 style = { this . props . style }
90- onPress = { this . props . onClick }
101+ onPress = { ( ) => this . onClick ( ) }
91102 underlayColor = 'transparent'
92103 disabled = { this . props . disabled }
93104 >
0 commit comments