Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Libraries/Components/DatePicker/DatePickerIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ const DatePickerIOS = createReactClass({
* instance, to show times in Pacific Standard Time, pass -7 * 60.
*/
timeZoneOffsetInMinutes: PropTypes.number,

/**
* DatePicker locale.
*
* By default, date picker locale is based on users locale. Using this parameter
* you can manually change it.
*/
locale: PropTypes.string,
},

getDefaultProps: function(): DefaultProps {
Expand Down Expand Up @@ -137,6 +145,7 @@ const DatePickerIOS = createReactClass({
mode={props.mode}
minuteInterval={props.minuteInterval}
timeZoneOffsetInMinutes={props.timeZoneOffsetInMinutes}
locale={props.locale || undefined}
onChange={this._onChange}
onStartShouldSetResponder={() => true}
onResponderTerminationRequest={() => false}
Expand Down
16 changes: 16 additions & 0 deletions RNTester/js/DatePickerIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ class DatePickerExample extends React.Component<$FlowFixMeProps, $FlowFixMeState
static defaultProps = {
date: new Date(),
timeZoneOffsetInHours: (-1) * (new Date()).getTimezoneOffset() / 60,
locale: false,
};

state = {
date: this.props.date,
timeZoneOffsetInHours: this.props.timeZoneOffsetInHours,
locale: this.props.locale,
};

onDateChange = (date) => {
Expand All @@ -44,6 +46,10 @@ class DatePickerExample extends React.Component<$FlowFixMeProps, $FlowFixMeState
this.setState({timeZoneOffsetInHours: offset});
};

onLocaleChange = (event) => {
this.setState({locale: event.nativeEvent.text});
};

render() {
// Ideally, the timezone input would be a picker rather than a
// text input, but we don't have any pickers yet :(
Expand All @@ -64,25 +70,35 @@ class DatePickerExample extends React.Component<$FlowFixMeProps, $FlowFixMeState
/>
<Text> hours from UTC</Text>
</WithLabel>
<WithLabel label="Locale:">
<TextInput
onChange={this.onLocaleChange}
style={styles.textinput}
value={this.state.locale}
/>
</WithLabel>
<Heading label="Date + time picker" />
<DatePickerIOS
date={this.state.date}
mode="datetime"
timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours * 60}
onDateChange={this.onDateChange}
locale={this.state.locale}
/>
<Heading label="Date picker" />
<DatePickerIOS
date={this.state.date}
mode="date"
timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours * 60}
onDateChange={this.onDateChange}
locale={this.state.locale}
/>
<Heading label="Time picker, 10-minute interval" />
<DatePickerIOS
date={this.state.date}
mode="time"
timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours * 60}
locale={this.state.locale}
onDateChange={this.onDateChange}
minuteInterval={10}
/>
Expand Down
5 changes: 5 additions & 0 deletions React/Views/RCTDatePickerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ - (UIView *)view
return [RCTDatePicker new];
}

RCT_CUSTOM_VIEW_PROPERTY(locale, NSString, UIDatePicker)
{
[view setLocale:[NSLocale localeWithLocaleIdentifier:json ? [RCTConvert NSString:json] : defaultView.locale.localeIdentifier]];
}

RCT_EXPORT_VIEW_PROPERTY(date, NSDate)
RCT_EXPORT_VIEW_PROPERTY(minimumDate, NSDate)
RCT_EXPORT_VIEW_PROPERTY(maximumDate, NSDate)
Expand Down