Skip to content

Commit be30731

Browse files
committed
feat(datepicker): add androidMode property for DatePickerAndroid & TimePickerAndroid
#85
1 parent 1bfa72b commit be30731

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ You can check [index.js](https://github.com/xgfe/react-native-datepicker/blob/ma
7272
| style | - | `object` | Specify the style of the DatePicker, eg. width, height... |
7373
| date | - | `string | date` | Specify the display date of DatePicker. `string` type value must match the specified format |
7474
| mode | 'date' | `enum` | The `enum` of `date`, `datetime` and `time` |
75+
| androidMode | 'default' | `enum` | The `enum` of `default`, `calendar` and `spinner` (only Android) |
7576
| 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. |
7677
| confirmBtnText | '确定' | `string` | Specify the text of confirm btn in ios. |
7778
| cancelBtnText | '取消' | `string` | Specify the text of cancel btn in ios. |

index.android.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ class datepicker extends Component {
3434

3535
render() {
3636
return (
37-
<View style={styles.container}
38-
{...this._panResponder.panHandlers}
39-
>
37+
<View style={styles.container}>
4038
<Text style={styles.welcome}>
4139
Welcome to react-native-datepicker example!
4240
</Text>

index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,16 @@ class DatePicker extends Component {
184184
}
185185

186186
onDatetimePicked({action, year, month, day}) {
187-
const {mode, format = FORMATS[mode], is24Hour = !format.match(/h|a/)} = this.props;
187+
const {mode, androidMode, format = FORMATS[mode], is24Hour = !format.match(/h|a/)} = this.props;
188188

189189
if (action !== DatePickerAndroid.dismissedAction) {
190190
let timeMoment = Moment(this.state.date);
191191

192192
TimePickerAndroid.open({
193193
hour: timeMoment.hour(),
194194
minute: timeMoment.minutes(),
195-
is24Hour: is24Hour
195+
is24Hour: is24Hour,
196+
androidMode
196197
}).then(this.onDatetimeTimePicked.bind(this, year, month, day));
197198
}
198199
}
@@ -220,14 +221,15 @@ class DatePicker extends Component {
220221
this.setModalVisible(true);
221222
} else {
222223

223-
const {mode, format = FORMATS[mode], minDate, maxDate, is24Hour = !format.match(/h|a/)} = this.props;
224+
const {mode, androidMode, format = FORMATS[mode], minDate, maxDate, is24Hour = !format.match(/h|a/)} = this.props;
224225

225226
// 选日期
226227
if (mode === 'date') {
227228
DatePickerAndroid.open({
228229
date: this.state.date,
229230
minDate: minDate && this.getDate(minDate),
230-
maxDate: maxDate && this.getDate(maxDate)
231+
maxDate: maxDate && this.getDate(maxDate),
232+
androidMode
231233
}).then(this.onDatePicked);
232234
} else if (mode === 'time') {
233235
// 选时间
@@ -245,7 +247,8 @@ class DatePicker extends Component {
245247
DatePickerAndroid.open({
246248
date: this.state.date,
247249
minDate: minDate && this.getDate(minDate),
248-
maxDate: maxDate && this.getDate(maxDate)
250+
maxDate: maxDate && this.getDate(maxDate),
251+
androidMode
249252
}).then(this.onDatetimePicked);
250253
}
251254
}
@@ -355,6 +358,7 @@ class DatePicker extends Component {
355358

356359
DatePicker.defaultProps = {
357360
mode: 'date',
361+
androidMode: 'default',
358362
date: '',
359363
// component height: 216(DatePickerIOS) + 1(borderTop) + 42(marginTop), IOS only
360364
height: 259,
@@ -375,6 +379,7 @@ DatePicker.defaultProps = {
375379

376380
DatePicker.propTypes = {
377381
mode: React.PropTypes.oneOf(['date', 'datetime', 'time']),
382+
androidMode: React.PropTypes.oneOf(['calendar', 'spinner', 'default']),
378383
date: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.instanceOf(Date)]),
379384
format: React.PropTypes.string,
380385
minDate: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.instanceOf(Date)]),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-datepicker",
3-
"version": "1.4.5",
3+
"version": "1.4.6",
44
"description": "react native datePicker component for both Android and IOS, useing DatePikcerAndroid, TimePickerAndroid and DatePickerIOS",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)