react-native-datetimepicker / datetimepicker

React Native date & time picker component for iOS, Android and Windows
MIT License
2.53k stars 413 forks source link

feat: Add set first day week android #902

Closed JoshBarnesD closed 5 months ago

JoshBarnesD commented 6 months ago

Summary

This feature provides the optional firstDayOfWeek functionality to the DatePicker on Android (currently only available in Windows). I was looking for tasks to get started with in the project and I saw this was a pending issue #196, so I decided to implement it.

Although the issue itself is quite old, hopefully it is still useful for someone.

How did you implement the solution?

As suggested in the issue thread, https://developer.android.com/reference/android/widget/DatePicker#setFirstDayOfWeek(int) provides the functionality to the Android DatePicker so that is what was used to implement it. The rest was simply bridging the props from React Native component to Android.

The firstDayOfWeek prop accepts the DAY_OF_WEEK constant to set the first day of the week.

NOTE: The DAY_OF_WEEK constant was used for consistency between the original Windows implementation and the new Android one. This does however mean that once the prop is parsed in the Android component it adds a +1 to it since the integers for setFirstDayOfWeek are 1-indexed instead of 0-indexed.

closes #196

Test Plan

Some examples of the UI changes when selecting different firstDayOfWeek:

firstDayOfWeek set to Sunday firstDayOfWeek set to Wednesday
Screenshot 2024-05-29 at 15 40 31 Screenshot 2024-05-29 at 15 51 25

Screenshot 2024-05-30 at 10 29 54 (Ran e2e tests for release on an emulated Pixel 6 Pro with API 30 and phone TZ set to Prague)

What's required for testing (prerequisites)?

e2e tests have been added to the project checking the functionality. These detox tests are only run on Android.

What are the steps to reproduce (after prerequisites)?

I have added a row of buttons to the example App which allow swapping the firstDayOfWeek for any day of the week. These are used in the e2e tests. I have also added a line to the upper info section of the example App which shows the current firstDayOfWeek value (defaults to Sunday).

Comments

Some of the included changes modify existing e2e tests as they seem to have stopped working due to the UI changes done to the example App. Some of these changes include:

As a side note, I have seen that there are a few e2e tests that fail on iOS (even on master) when I test them locally, specifically those that use the spinner implementation of the DateTimePicker.

Compatibility

OS Implemented
iOS
Android

Checklist

vonovak commented 5 months ago

:tada: This issue has been resolved in version 8.1.0 :tada:

If this package helps you, consider sponsoring us! :rocket: