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: create expo plugin to customize native style #801

Conversation

brunohkbx
Copy link
Contributor

@brunohkbx brunohkbx commented Aug 10, 2023

Summary

This PR is a proposal to implement an expo plugin to be able to customize both Android native components DatePickerDialog and TimePickerDialog.

Resolves #20

References
https://www.tutorialsbuzz.com/2019/09/android-datepicker-dialog-styling-kotlin.html
https://www.tutorialsbuzz.com/2019/09/android-timepicker-dialog-styling.html

Test Plan

DatePickerDialog TimePickerDialog
Screenshot from 2023-08-10 02-48-29 Screenshot from 2023-08-09 23-10-30

styles.xml

Entries added in the style <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

<item name="android:datePickerDialogTheme">@style/DatePickerDialogTheme</item>
<item name="android:timePickerStyle">@style/TimePickerTheme</item>

New style entries added

<style name="DatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
  <item name="colorAccent">@color/datePicker_colorAccent</item>
  <item name="colorControlActivated">@color/datePicker_colorControlActivated</item>
  <item name="colorControlHighlight">@color/datePicker_colorControlHighlight</item>
  <item name="android:textColor">@color/datePicker_textColor</item>
  <item name="android:textColorPrimary">@color/datePicker_textColorPrimary</item>
  <item name="android:textColorSecondary">@color/datePicker_textColorSecondary</item>
  <item name="android:windowBackground">@color/datePicker_windowBackground</item>
</style>

<style name="TimePickerTheme" parent="android:Widget.Material.Light.TimePicker">
  <item name="android:background">@color/timePicker_background</item>
</style>

colors.xml

<resources>
  <color name="datePicker_colorAccent">...</color>
  <color name="datePicker_colorControlActivated">...</color>
  <color name="datePicker_colorControlHighlight">...</color>
  <color name="datePicker_textColor">...</color>
  <color name="datePicker_textColorPrimary">...</color>
  <color name="datePicker_textColorSecondary">...</color>
  <color name="datePicker_windowBackground">...</color>
  <color name="timePicker_background">...</color>
</resources>

values-night/colors.xml

<resources>
  <color name="datePicker_colorAccent">...</color>
  <color name="datePicker_colorControlActivated">...</color>
  <color name="datePicker_colorControlHighlight">...</color>
  <color name="datePicker_textColor">...</color>
  <color name="datePicker_textColorPrimary">...</color>
  <color name="datePicker_textColorSecondary">...</color>
  <color name="datePicker_windowBackground">...</color>
  <color name="timePicker_background">...</color>
</resources>

What's required for testing (prerequisites)?

  1. First of, set up a new expo project with expo init
  2. Install this library with expo install @react-native-community/datetimepicker
  3. Configure the new plugin in app.json/app.config.js as described in the new documentation

What are the steps to reproduce (after prerequisites)?

You should see the new styles applied to either a RNDateTimePicker with mode="date" or mode="time"

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

colorAccent: {attrName: 'colorAccent', colorName: 'datePicker_colorAccent'},
colorControlActivated: {
attrName: 'colorControlActivated',
colorName: 'datePicker_colorControlActivated',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is a good idea, but I added the prefix datePicker_ and timePicker_ for the new colors to avoid polluting the global scope just in case.

docs/android-styling.md Outdated Show resolved Hide resolved
plugin/src/withDateTimePickerStyles.ts Outdated Show resolved Hide resolved
@Haukez
Copy link

Haukez commented Nov 28, 2023

I guess we'll have to wait until like 2025.

@mribbons
Copy link

@brunohkbx anything we can do to help move this forward?

@vonovak vonovak enabled auto-merge (squash) July 9, 2024 13:48
@vonovak
Copy link
Member

vonovak commented Jul 9, 2024

To give an answer to @mribbons and @Haukez - to move a stale PR forward, you can fork the original branch, address the comments from the review, write docs, test the implementation and submit a new PR 🙂.

This PR will be merged soon.

Thank you @brunohkbx!

@vonovak vonovak merged commit 66235db into react-native-datetimepicker:master Jul 9, 2024
5 checks passed
vonovak pushed a commit that referenced this pull request Jul 9, 2024
# [8.2.0](v8.1.1...v8.2.0) (2024-07-09)

### Bug Fixes

* **android:** improve color resource handling in Common.java ([#913](#913)) ([8527354](8527354))

### Features

* create expo plugin to customize native style ([#801](#801)) ([66235db](66235db))
@vonovak
Copy link
Member

vonovak commented Jul 9, 2024

🎉 This issue has been resolved in version 8.2.0 🎉

If this package helps you, consider sponsoring us! 🚀

@fax1ty
Copy link

fax1ty commented Oct 1, 2024

@vonovak What about textColor for TimePicker?
image

@vonovak
Copy link
Member

vonovak commented Oct 1, 2024

@fax1ty see https://github.com/react-native-datetimepicker/datetimepicker#positivebutton-optional-android-only

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.

Please add props to change theme color of the picker.
6 participants