diff --git a/README.md b/README.md index fd3275861e..f0c00c5ef3 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ You can check [index.js](https://github.com/xgfe/react-native-datepicker/blob/ma | customStyles | - | `number` | The hook of customize datepicker style, same as the native style. `dateTouchBody`, `dateInput`...| | showIcon | true | `boolean` | Controller whether or not show the icon | | disabled | false | `boolean` | Controller whether or not disable the picker | +| is24Hour | - | `boolean` | Set the TimePicker is24Hour flag. The default value depend on `format`. Only work in Android | | placeholder | '' | `string` | The placeholder show when this.props.date is falsy | | onDateChange | - | `function` | This is called when the user confirm the picked date or time in the UI. The first and only argument is a date or time string representing the new date and time formatted by [moment.js](http://momentjs.com/) with the given format property. | | modalOnResponderTerminationRequest | - | `function` | Set the callback for React Native's [Gesture Responder System](https://facebook.github.io/react-native/docs/gesture-responder-system.html#responder-lifecycle)'s call to `onResponderTerminationRequest`. By default this will reject a termination request, but can be overidden in case the View under the Modal is implementing custom gesture responders, and you wish for those to be overidden in certain cases. | diff --git a/index.js b/index.js index a63913b52a..ebb4e8a152 100644 --- a/index.js +++ b/index.js @@ -159,12 +159,13 @@ class DatePicker extends Component { onDatetimePicked({action, year, month, day}) { if (action !== DatePickerAndroid.dismissedAction) { + const {is24Hour = !this.format.match(/h|a/)} = this.props; let timeMoment = Moment(this.state.date); TimePickerAndroid.open({ hour: timeMoment.hour(), minute: timeMoment.minutes(), - is24Hour: !this.format.match(/h|a/) + is24Hour: is24Hour }).then(this.onDatetimeTimePicked.bind(this, year, month, day)); } } @@ -191,6 +192,7 @@ class DatePicker extends Component { if (Platform.OS === 'ios') { this.setModalVisible(true); } else { + const {is24Hour = !this.format.match(/h|a/)} = this.props; // 选日期 if (this.props.mode === 'date') { @@ -207,7 +209,7 @@ class DatePicker extends Component { TimePickerAndroid.open({ hour: timeMoment.hour(), minute: timeMoment.minutes(), - is24Hour: !this.format.match(/h|a/) + is24Hour: is24Hour }).then(this.onTimePicked); } else if (this.props.mode === 'datetime') { // 选日期和时间 @@ -341,7 +343,8 @@ DatePicker.propTypes = { disabled: React.PropTypes.bool, onDateChange: React.PropTypes.func, placeholder: React.PropTypes.string, - modalOnResponderTerminationRequest: React.PropTypes.func + modalOnResponderTerminationRequest: React.PropTypes.func, + is24Hour: React.PropTypes.bool }; export default DatePicker;