diff --git a/README.md b/README.md index c089e0ae..0e39d4e1 100644 --- a/README.md +++ b/README.md @@ -144,15 +144,15 @@ Autolinking is not yet implemented on Windows, so [manual installation ](/docs/m If you are using RN >= 0.60, only run `npx pod-install`. Then rebuild your project. ## React Native Support -Check the `react-native` version support table below to find the corrosponding `datetimepicker` version to meet support requirements. -| react-native version | version | -| -------------------- | -------- | -| 0.73.0+ | 7.6.3+ | -| <=0.72.0 | <=7.6.2 | -| 0.70.0+ | 7.0.1+ | -| <0.70.0 | <=7.0.0 | +Check the `react-native` version support table below to find the corresponding `datetimepicker` version to meet support requirements. +| react-native version | version | +| -------------------- | ------- | +| 0.73.0+ | 7.6.3+ | +| <=0.72.0 | <=7.6.2 | +| 0.70.0+ | 7.0.1+ | +| <0.70.0 | <=7.0.0 | ## Usage @@ -424,7 +424,7 @@ Reference: https://docs.microsoft.com/en-us/uwp/api/windows.globalization.dateti ``` -#### `firstDayOfWeek` (`optional`, `Windows only`) +#### `firstDayOfWeek` (`optional`, `Android and Windows only`) Indicates which day is shown as the first day of the week. diff --git a/android/src/main/java/com/reactcommunity/rndatetimepicker/DatePickerModule.java b/android/src/main/java/com/reactcommunity/rndatetimepicker/DatePickerModule.java index c7272205..6eec370b 100644 --- a/android/src/main/java/com/reactcommunity/rndatetimepicker/DatePickerModule.java +++ b/android/src/main/java/com/reactcommunity/rndatetimepicker/DatePickerModule.java @@ -184,6 +184,11 @@ private Bundle createFragmentArguments(ReadableMap options) { if (options.hasKey(RNConstants.ARG_TESTID) && !options.isNull(RNConstants.ARG_TESTID)) { args.putString(RNConstants.ARG_TESTID, options.getString(RNConstants.ARG_TESTID)); } + if (options.hasKey(RNConstants.FIRST_DAY_OF_WEEK) && !options.isNull(RNConstants.FIRST_DAY_OF_WEEK)) { + // FIRST_DAY_OF_WEEK is 0-indexed, since it uses the same constants DAY_OF_WEEK used in the Windows implementation + // Android DatePicker uses 1-indexed values, SUNDAY being 1 and SATURDAY being 7, so the +1 is necessary in this case + args.putInt(RNConstants.FIRST_DAY_OF_WEEK, options.getInt(RNConstants.FIRST_DAY_OF_WEEK)+1); + } return args; } } diff --git a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNConstants.java b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNConstants.java index 99530d51..acb56cb9 100644 --- a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNConstants.java +++ b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNConstants.java @@ -18,6 +18,7 @@ public final class RNConstants { public static final String ACTION_TIME_SET = "timeSetAction"; public static final String ACTION_DISMISSED = "dismissedAction"; public static final String ACTION_NEUTRAL_BUTTON = "neutralButtonAction"; + public static final String FIRST_DAY_OF_WEEK = "firstDayOfWeek"; /** * Minimum date supported by {@link TimePickerDialog}, 01 Jan 1900 diff --git a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogFragment.java b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogFragment.java index 72de7cbb..eeb19702 100644 --- a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogFragment.java +++ b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogFragment.java @@ -116,8 +116,11 @@ private DatePickerDialog createDialog(Bundle args) { // the date under certain conditions. datePicker.setMinDate(RNConstants.DEFAULT_MIN_DATE); } - if (args.containsKey(RNConstants.ARG_MAXDATE)) { - datePicker.setMaxDate(maxDate); + + // Only compatible with SDK 21 and above + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && args.containsKey(RNConstants.FIRST_DAY_OF_WEEK)) { + final int firstDayOfWeek = args.getInt(RNConstants.FIRST_DAY_OF_WEEK); + datePicker.setFirstDayOfWeek(firstDayOfWeek); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && (args.containsKey(RNConstants.ARG_MAXDATE) || args.containsKey(RNConstants.ARG_MINDATE))) { diff --git a/example/App.js b/example/App.js index 2190714c..6788cdee 100644 --- a/example/App.js +++ b/example/App.js @@ -111,7 +111,7 @@ export const App = () => { const [maxDate] = useState(new Date('2021')); const [minDate] = useState(new Date('2018')); const [is24Hours, set24Hours] = useState(false); - const [firstDayOfWeek, setFirstDayOfWeek] = useState(DAY_OF_WEEK.Monday); + const [firstDayOfWeek, setFirstDayOfWeek] = useState(DAY_OF_WEEK.Sunday); const [dateFormat, setDateFormat] = useState('longdate'); const [dayOfWeekFormat, setDayOfWeekFormat] = useState( '{dayofweek.abbreviated(2)}', @@ -168,7 +168,7 @@ export const App = () => { : `${item} mins` : item; return ( - +