Skip to content

Commit

Permalink
feat: add back locale prop (#544)
Browse files Browse the repository at this point in the history
* Revert "feat: remove locale prop (#540)"

This reverts commit 6637c03.

* chore: update docs and minor changes

* fix screenshot?

* improve docs and screenshot
  • Loading branch information
vonovak authored Dec 20, 2021
1 parent ea20f45 commit 05f39fa
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 11 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module.exports = {
jest: true,
jasmine: true,
waitFor: true,
detoxCircus: true
}
detoxCircus: true,
},
rules: {
'no-var': 2,
},
};
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ React Native date & time picker component for iOS, Android and Windows.
<table>
<tr><td colspan=2><strong>iOS</strong></td></tr>
<tr>
<td><p align="center"><img src="./docs/images/ios_date.png" width="260" height="420"/></p></td>
<td><p align="center"><img src="./docs/images/ios_date_new.png" height="420"/></p></td>
<td><p align="center"><img src="./docs/images/ios_time.png" width="260" height="420"/></p></td>
</tr>
<tr><td colspan=2><strong>Android</strong></td></tr>
Expand Down Expand Up @@ -67,6 +67,7 @@ React Native date & time picker component for iOS, Android and Windows.
- [`firstDayOfWeek` (`optional`, `Windows only`)](#firstDayOfWeek-optional-windows-only)
- [`textColor` (`optional`, `iOS only`)](#textColor-optional-ios-only)
- [`themeVariant` (`optional`, `iOS only`)](#themeVariant-optional-ios-only)
- [`locale` (`optional`, `iOS only`)](#locale-optional-ios-only)
- [`is24Hour` (`optional`, `Windows and Android only`)](#is24hour-optional-windows-and-android-only)
- [`neutralButtonLabel` (`optional`, `Android only`)](#neutralbuttonlabel-optional-android-only)
- [`minuteInterval` (`optional`)](#minuteinterval-optional)
Expand Down Expand Up @@ -176,12 +177,14 @@ export const App = () => {
};
```

## Locale note
## Localization note

On Android, the picker will be controlled by the system locale. If you wish to change it, [see instructions here](https://stackoverflow.com/a/2900144/2070942).

On iOS, the locale can be controlled from xCode, as [documented here](https://developer.apple.com/documentation/xcode/adding-support-for-languages-and-regions).

There is also the iOS-only locale prop that can be used to force locale in some cases but its usage is discouraged due to [not working robustly in all picker modes](./docs/images/ios_date_new.png) (note the mixed month and day names).

For Expo, follow the [localization docs](https://docs.expo.dev/distribution/app-stores/#localizing-your-ios-app).

## Props
Expand Down Expand Up @@ -317,6 +320,15 @@ Allows changing of the textColor of the date picker. Has effect only when `displ
<RNDateTimePicker textColor="red" />
```

#### `locale` (`optional`, `iOS only`)

Allows changing the locale of the component. By default, the device's locale is used. Please note using this prop is discouraged due to not working reliably in all picker modes.
Prefer localization as documented in [Localization note](#localization-note).

```js
<RNDateTimePicker locale="es-ES" />
```

#### `is24Hour` (`optional`, `Windows and Android only`)

Allows changing of the time picker to a 24 hour format. By default, this value is decided automatcially based on the user's chosen locale and other preferences.
Expand Down
Binary file added docs/images/ios_date_new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
6 changes: 4 additions & 2 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export const App = () => {
backgroundColor: isDarkMode ? Colors.dark : Colors.lighter,
};

const toggleMinMaxDate = () => {
const toggleMinMaxDateInUTC = () => {
setTzOffsetInMinutes(0);

const startOfTodayUTC = sourceMoment.utc().startOf('day').toDate();
setMinimumDate(maximumDate ? undefined : startOfTodayUTC);
const endOfTomorrowUTC = sourceMoment
Expand Down Expand Up @@ -285,7 +287,7 @@ export const App = () => {
<Button
testID="setMinMax"
onPress={() => {
toggleMinMaxDate();
toggleMinMaxDateInUTC();
setShow(true);
}}
title="toggleMinMaxDate"
Expand Down
9 changes: 4 additions & 5 deletions example/e2e/detoxTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ describe('Example', () => {

it('should let you pick tomorrow but not yesterday when setting min/max', async () => {
await elementById('DateTimePickerScrollView').scrollTo('bottom');
await elementById('setTzOffsetToZero').tap();
await elementById('setMinMax').tap();

if (isIOS()) {
Expand All @@ -207,10 +206,10 @@ describe('Example', () => {

// Ensure you can't select yesterday (Android)
const focusTwelethOfNovemberInCalendar = async () => {
for (var i = 0; i < 4; i++) {
for (let i = 0; i < 4; i++) {
await uiDevice.pressDPadDown();
}
for (var i = 0; i < 3; i++) {
for (let i = 0; i < 3; i++) {
await uiDevice.pressDPadLeft();
}
};
Expand All @@ -222,10 +221,10 @@ describe('Example', () => {
// Ensure you can select tomorrow (Android)
await userOpensPicker({mode: 'date', display: getPickerDisplay()});
const focusFourteenthOfNovemberInCalendar = async () => {
for (var i = 0; i < 5; i++) {
for (let i = 0; i < 5; i++) {
await uiDevice.pressDPadDown();
}
for (var i = 0; i < 2; i++) {
for (let i = 0; i < 2; i++) {
await uiDevice.pressDPadLeft();
}
};
Expand Down
1 change: 1 addition & 0 deletions ios/RNDateTimePickerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ + (NSString*) datepickerStyleToString: (UIDatePickerStyle) style API_AVAILABLE(
}

RCT_EXPORT_VIEW_PROPERTY(date, NSDate)
RCT_EXPORT_VIEW_PROPERTY(locale, NSLocale)
RCT_EXPORT_VIEW_PROPERTY(minimumDate, NSDate)
RCT_EXPORT_VIEW_PROPERTY(maximumDate, NSDate)
RCT_EXPORT_VIEW_PROPERTY(minuteInterval, NSInteger)
Expand Down
2 changes: 2 additions & 0 deletions src/datetimepicker.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const getDisplaySafe = (display: IOSDisplay): IOSDisplay => {

export default function Picker({
value,
locale,
maximumDate,
minimumDate,
style,
Expand Down Expand Up @@ -115,6 +116,7 @@ export default function Picker({
ref={_picker}
style={StyleSheet.compose(heightStyle, style)}
date={dates.value}
locale={locale !== null && locale !== '' ? locale : undefined}
maximumDate={dates.maximumDate}
minimumDate={dates.minimumDate}
mode={mode}
Expand Down
5 changes: 5 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export type IOSNativeProps = Readonly<
BaseProps & {
date?: Date;

/**
* The date picker locale.
*/
locale?: string;

/**
* The interval at which minutes can be selected.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export type IOSNativeProps = $ReadOnly<{|
...BaseProps,
date?: ?Date,

/**
* The date picker locale.
*/
locale?: ?string,

/**
* The interval at which minutes can be selected.
*/
Expand Down

0 comments on commit 05f39fa

Please sign in to comment.