Skip to content

Commit

Permalink
Merge pull request #1 from mat1th/feature/right-text
Browse files Browse the repository at this point in the history
add ability to add right text.
  • Loading branch information
crazycodeboy authored Oct 14, 2016
2 parents 9e9e5bb + 06e3599 commit 1bbe2a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Props | Type | Optional | Default | Description
----------------- | -------- | -------- | ----------- | -----------
style | View.propTypes.style | true | | Custom style checkbox
leftText | React.PropTypes.string |true | | Custom left Text
rightText | React.PropTypes.string |true | | Custom right Text
checkedImage | React.PropTypes.element | true | Default image | Custom checked Image
unCheckedImage | React.PropTypes.element | true | Default image | Custom unchecked Image
isChecked | React.PropTypes.bool | true | false | Initialization checkbox checked
Expand Down
20 changes: 16 additions & 4 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 Down Expand Up @@ -29,6 +29,8 @@ export default class CheckBox extends Component {
...View.propTypes,
leftText: React.PropTypes.string,
leftTextView: React.PropTypes.element,
rightText: React.PropTypes.string,
rightTextView: React.PropTypes.string,
checkedImage: React.PropTypes.element,
unCheckedImage: React.PropTypes.element,
onClick: React.PropTypes.func.isRequired,
Expand All @@ -46,6 +48,13 @@ export default class CheckBox extends Component {
<Text style={styles.leftText}>{this.props.leftText}</Text>
)
}
_renderRight() {
if (this.props.rightTextView)return this.props.rightTextView;
if (!this.props.rightText)return null;
return (
<Text style={styles.rightText}>{this.props.rightText}</Text>
)
}

_renderImage() {
if (this.state.isChecked) {
Expand Down Expand Up @@ -80,6 +89,7 @@ export default class CheckBox extends Component {
<View style={styles.container}>
{this._renderLeft()}
{this._renderImage()}
{this._renderRight()}
</View>
</TouchableHighlight>
)
Expand All @@ -89,10 +99,12 @@ const styles = StyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center'
// backgroundColor:'gray'
},
leftText: {
flex: 1,
// backgroundColor:'red',
},
rightText: {
flex: 1,
marginLeft: 10
}
})
})

0 comments on commit 1bbe2a3

Please sign in to comment.