Skip to content

Commit 1bbd66e

Browse files
committedMay 6, 2016
feat(datepicker): add support for custom btn text
1 parent 71c4bb6 commit 1bbd66e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
 

‎README.md

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Check [index.js](https://github.com/xgfe/react-native-datepicker/blob/master/exa
2323
format="YYYY-MM-DD"
2424
minDate="2016-05-01"
2525
maxDate="2016-06-01"
26+
confirmBtnText="Confirm"
27+
cancelBtnText="Cancel"
2628
onDateChange={(date) => {this.setState({date: date})}}
2729
/>
2830
```
@@ -37,6 +39,8 @@ You can check [index.js](https://github.com/xgfe/react-native-datepicker/blob/ma
3739
| date | - | `string | date` | Specify the display date of DatePicker. `string` type value must match the specified format |
3840
| mode | 'date' | `enum` | The `enum` of `date`, `datetime` and `time` |
3941
| format | 'YYYY-MM-DD' | `string` | Specify the display format of the date, which using [moment.js](http://momentjs.com/). The default value change according to the mode. |
42+
| confirmBtnText | - | `string` | Specify the text of confirm btn in ios. |
43+
| cancelBtnText | - | `string` | Specify the text of cancel btn in ios. |
4044
| minDate | - | `string | date` | Restricts the range of possible date values. |
4145
| maxDate | - | `string | date` | Restricts the range of possible date values. |
4246
| duration | 300 | `number` | Specify the animation duration of datepicker.

‎example/index.android.js

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class example extends Component {
3434
format="YYYY-MM-DD"
3535
minDate="2016-05-01"
3636
maxDate="2016-06-01"
37+
confirmBtnText="Confirm"
38+
cancelBtnText="Cancel"
3739
onDateChange={(date) => {this.setState({date: date})}}
3840
/>
3941
<Text style={styles.instructions}>date: {this.state.date}</Text>
@@ -42,6 +44,8 @@ class example extends Component {
4244
date={this.state.time}
4345
mode="time"
4446
format="HH:mm"
47+
confirmBtnText="Confirm"
48+
cancelBtnText="Cancel"
4549
onDateChange={(time) => {this.setState({time: time})}}
4650
/>
4751
<Text style={styles.instructions}>time: {this.state.time}</Text>
@@ -50,6 +54,8 @@ class example extends Component {
5054
date={this.state.datetime}
5155
mode="datetime"
5256
format="YYYY-MM-DD HH:mm"
57+
confirmBtnText="Confirm"
58+
cancelBtnText="Cancel"
5359
onDateChange={(datetime) => {this.setState({datetime: datetime})}}
5460
/>
5561
<Text style={styles.instructions}>datetime: {this.state.datetime}</Text>

‎index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class DatePicker extends Component {
4141
// slide animation duration time, default to 300ms, IOS only
4242
duration = this.props.duration || 300;
4343

44+
confirmBtnText = this.props.confirmBtnText || '确定';
45+
cancelBtnText = this.props.cancelBtnText || '取消';
46+
4447
state = {
4548
date: this.getDate(),
4649
modalVisible: false,
@@ -231,14 +234,14 @@ class DatePicker extends Component {
231234
onPress={this.onPressCancel}
232235
style={[Style.btnText, Style.btnCancel]}
233236
>
234-
<Text style={[Style.btnTextText, Style.btnTextCancel]}>取消</Text>
237+
<Text style={[Style.btnTextText, Style.btnTextCancel]}>{this.cancelBtnText}</Text>
235238
</TouchableHighlight>
236239
<TouchableHighlight
237240
underlayColor={'transparent'}
238241
onPress={this.onPressConfirm}
239242
style={[Style.btnText, Style.btnConfirm]}
240243
>
241-
<Text style={Style.btnTextText}>确定</Text>
244+
<Text style={Style.btnTextText}>{this.confirmBtnText}</Text>
242245
</TouchableHighlight>
243246
</Animated.View>
244247
</TouchableHighlight>

0 commit comments

Comments
 (0)
Please sign in to comment.