Skip to content

Commit 1bbe2a3

Browse files
authored
Merge pull request #1 from mat1th/feature/right-text
add ability to add right text.
2 parents 9e9e5bb + 06e3599 commit 1bbe2a3

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Props | Type | Optional | Default | Description
8080
----------------- | -------- | -------- | ----------- | -----------
8181
style | View.propTypes.style | true | | Custom style checkbox
8282
leftText | React.PropTypes.string |true | | Custom left Text
83+
rightText | React.PropTypes.string |true | | Custom right Text
8384
checkedImage | React.PropTypes.element | true | Default image | Custom checked Image
8485
unCheckedImage | React.PropTypes.element | true | Default image | Custom unchecked Image
8586
isChecked | React.PropTypes.bool | true | false | Initialization checkbox checked

index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
@@ -29,6 +29,8 @@ export default class CheckBox extends Component {
2929
...View.propTypes,
3030
leftText: React.PropTypes.string,
3131
leftTextView: React.PropTypes.element,
32+
rightText: React.PropTypes.string,
33+
rightTextView: React.PropTypes.string,
3234
checkedImage: React.PropTypes.element,
3335
unCheckedImage: React.PropTypes.element,
3436
onClick: React.PropTypes.func.isRequired,
@@ -46,6 +48,13 @@ export default class CheckBox extends Component {
4648
<Text style={styles.leftText}>{this.props.leftText}</Text>
4749
)
4850
}
51+
_renderRight() {
52+
if (this.props.rightTextView)return this.props.rightTextView;
53+
if (!this.props.rightText)return null;
54+
return (
55+
<Text style={styles.rightText}>{this.props.rightText}</Text>
56+
)
57+
}
4958

5059
_renderImage() {
5160
if (this.state.isChecked) {
@@ -80,6 +89,7 @@ export default class CheckBox extends Component {
8089
<View style={styles.container}>
8190
{this._renderLeft()}
8291
{this._renderImage()}
92+
{this._renderRight()}
8393
</View>
8494
</TouchableHighlight>
8595
)
@@ -89,10 +99,12 @@ const styles = StyleSheet.create({
8999
container: {
90100
flexDirection: 'row',
91101
alignItems: 'center'
92-
// backgroundColor:'gray'
93102
},
94103
leftText: {
95104
flex: 1,
96-
// backgroundColor:'red',
105+
},
106+
rightText: {
107+
flex: 1,
108+
marginLeft: 10
97109
}
98-
})
110+
})

0 commit comments

Comments
 (0)