Skip to content

Commit

Permalink
fix #39 #37
Browse files Browse the repository at this point in the history
  • Loading branch information
午天 committed Oct 10, 2017
1 parent 9f4bec7 commit 456576b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* react-native-check-box
* Checkbox component for react native, it works on iOS and Android
* https://github.com/crazycodeboy/react-native-check-box
Expand All @@ -20,6 +20,12 @@ import PropTypes from 'prop-types';


export default class CheckBox extends Component {
constructor(props) {
super(props);
this.state = {
isChecked: this.props.isChecked,
}
}
static propTypes = {
...(ViewPropTypes || View.PropTypes),
leftText: PropTypes.string,
Expand All @@ -42,7 +48,12 @@ export default class CheckBox extends Component {
leftTextStyle: {},
rightTextStyle: {}
}

onClick() {
this.setState({
isChecked: !this.state.isChecked
})
this.props.onClick();
}
_renderLeft() {
if (this.props.leftTextView)return this.props.leftTextView;
if (!this.props.leftText)return null;
Expand All @@ -62,7 +73,7 @@ export default class CheckBox extends Component {
if (this.props.isIndeterminate){
return this.props.indeterminateImage ? this.props.indeterminateImage : this.genCheckedImage();
}
if (this.props.isChecked) {
if (this.state.isChecked) {
return this.props.checkedImage ? this.props.checkedImage : this.genCheckedImage();
} else {
return this.props.unCheckedImage ? this.props.unCheckedImage : this.genCheckedImage();
Expand All @@ -72,10 +83,10 @@ export default class CheckBox extends Component {
genCheckedImage() {
var source;
if (this.props.isIndeterminate) {
source = require('./img/ic_indeterminate_check_box.png');
source = require('./img/ic_indeterminate_check_box.png');
}
else {
source = this.props.isChecked ? require('./img/ic_check_box.png') : require('./img/ic_check_box_outline_blank.png');
source = this.state.isChecked ? require('./img/ic_check_box.png') : require('./img/ic_check_box_outline_blank.png');
}

return (
Expand All @@ -87,7 +98,7 @@ export default class CheckBox extends Component {
return (
<TouchableHighlight
style={this.props.style}
onPress={this.props.onClick}
onPress={()=>this.onClick()}
underlayColor='transparent'
disabled={this.props.disabled}
>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-check-box",
"version": "2.0.1",
"version": "2.0.2",
"description": "Checkbox component for react native, it works on iOS and Android.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 456576b

Please sign in to comment.