Skip to content

Commit c320e56

Browse files
committed
fix(datepicker): fix is24Hour flag can't be setted bug
#69
1 parent 7579dc9 commit c320e56

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ You can check [index.js](https://github.com/xgfe/react-native-datepicker/blob/ma
7676
| customStyles | - | `number` | The hook of customize datepicker style, same as the native style. `dateTouchBody`, `dateInput`...|
7777
| showIcon | true | `boolean` | Controller whether or not show the icon |
7878
| disabled | false | `boolean` | Controller whether or not disable the picker |
79+
| is24Hour | - | `boolean` | Set the TimePicker is24Hour flag. The default value depend on `format`. Only work in Android |
7980
| placeholder | '' | `string` | The placeholder show when this.props.date is falsy |
8081
| 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. |
8182
| 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. |

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,13 @@ class DatePicker extends Component {
159159

160160
onDatetimePicked({action, year, month, day}) {
161161
if (action !== DatePickerAndroid.dismissedAction) {
162+
const {is24Hour = !this.format.match(/h|a/)} = this.props;
162163
let timeMoment = Moment(this.state.date);
163164

164165
TimePickerAndroid.open({
165166
hour: timeMoment.hour(),
166167
minute: timeMoment.minutes(),
167-
is24Hour: !this.format.match(/h|a/)
168+
is24Hour: is24Hour
168169
}).then(this.onDatetimeTimePicked.bind(this, year, month, day));
169170
}
170171
}
@@ -191,6 +192,7 @@ class DatePicker extends Component {
191192
if (Platform.OS === 'ios') {
192193
this.setModalVisible(true);
193194
} else {
195+
const {is24Hour = !this.format.match(/h|a/)} = this.props;
194196

195197
// 选日期
196198
if (this.props.mode === 'date') {
@@ -207,7 +209,7 @@ class DatePicker extends Component {
207209
TimePickerAndroid.open({
208210
hour: timeMoment.hour(),
209211
minute: timeMoment.minutes(),
210-
is24Hour: !this.format.match(/h|a/)
212+
is24Hour: is24Hour
211213
}).then(this.onTimePicked);
212214
} else if (this.props.mode === 'datetime') {
213215
// 选日期和时间
@@ -341,7 +343,8 @@ DatePicker.propTypes = {
341343
disabled: React.PropTypes.bool,
342344
onDateChange: React.PropTypes.func,
343345
placeholder: React.PropTypes.string,
344-
modalOnResponderTerminationRequest: React.PropTypes.func
346+
modalOnResponderTerminationRequest: React.PropTypes.func,
347+
is24Hour: React.PropTypes.bool
345348
};
346349

347350
export default DatePicker;

0 commit comments

Comments
 (0)