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.
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
(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:
Added scroll down/up to some tests depending on necessity due to added buttons pushing some content out of view.
Added .multiTap(2) instead of .tap() to some tests as they occasionally failed. I suspect this is caused by the button trying to be tapped being inside a horizontal scrollview that doesn't finish scrolling before the tap on the button is triggered.
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
[x] I have tested this on a device and a simulator
[X] I added the documentation in README.md
[X] I updated the typed files (TS and Flow)
[X] I added a sample use of the API in the example project (example/App.js)
[X] I have added automated tests, either in JS or e2e tests, as applicable
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 theDAY_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:
(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 currentfirstDayOfWeek
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:
.multiTap(2)
instead of.tap()
to some tests as they occasionally failed. I suspect this is caused by the button trying to be tapped being inside a horizontal scrollview that doesn't finish scrolling before the tap on the button is triggered.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 theDateTimePicker
.Compatibility
Checklist
README.md
example/App.js
)