Skip to content

Commit

Permalink
fix(datepicker): fix is24Hour flag can't be setted bug
Browse files Browse the repository at this point in the history
  • Loading branch information
feyy committed Dec 13, 2016
1 parent 7579dc9 commit c320e56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand All @@ -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') {
Expand All @@ -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') {
// 选日期和时间
Expand Down Expand Up @@ -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;

0 comments on commit c320e56

Please sign in to comment.