Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add set first day week android #902

Conversation

JoshBarnesD
Copy link
Collaborator

@JoshBarnesD JoshBarnesD commented May 30, 2024

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:

  • 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

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I updated the typed files (TS and Flow)
  • I added a sample use of the API in the example project (example/App.js)
  • I have added automated tests, either in JS or e2e tests, as applicable

Copy link
Member

@vonovak vonovak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I like this!! :)

especially the detailed description. Makes it delightful to read code when I'm given context and screenshots and so on. Thank you, really :)

README.md Outdated Show resolved Hide resolved
<ThemedText style={styles.textLabel}>
firstDayOfWeek (android only)
</ThemedText>
<View style={styles.firstDayOfWeekContainer}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned you needed to add scrolling. Can we make this more compact in terms of height?

I'd prefer if we can avoid scrolling because it's annoying to think about it when maintaining tests.

Also the code seems fit to be replaced by a array.map

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off, thank you for the lovely comments you've made, they made my day! 😄

Now, with regards to this, Ive implemented a FlatList design for selecting the DAY_OF_WEEK variable (similar to the "timezone" FlatList further down) but, sadly, it seems most of the tests would still need to have some level of scrolling to access the UI elements... Either way I will push the changes shortly and you can check them out!

I've gone through most of the tests and I think it might be reasonable to implement a "ScrollToElement" function that allows you to scroll to the necessary UI element before interacting with it. This would also reduce the size and repetitiveness of some of the tests and hopefully aid with maintainability. I was thinking of maybe creating a separate PR going over them and addressing some of the issues. Let me know what you think!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, though if we can avoid scrolling, that'd be best imho. I see that now we run in iphone 14. A low-effort fix could be just bumping to a larger device.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will revert the changes to the tests that add scrolling and see if I can find a valid device for iOS and Android that will pass the tests without scrolling, will get back to you shortly

example/e2e/detoxTest.spec.js Show resolved Hide resolved
…tiveness and changed example App firstDayOfWeek selector to a FlatList
@JoshBarnesD JoshBarnesD requested a review from vonovak June 3, 2024 10:47
@vonovak vonovak enabled auto-merge (squash) June 3, 2024 14:55
@vonovak vonovak merged commit 3b63563 into react-native-datetimepicker:master Jun 3, 2024
5 checks passed
vonovak pushed a commit that referenced this pull request Jun 3, 2024
# [8.1.0](v8.0.1...v8.1.0) (2024-06-03)

### Features

* **android:** enable customizing first day of week ([#902](#902)) ([3b63563](3b63563))
@vonovak
Copy link
Member

vonovak commented Jun 3, 2024

🎉 This issue has been resolved in version 8.1.0 🎉

If this package helps you, consider sponsoring us! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change the default first day of the week on Android platform.
2 participants