datetimepicker icon indicating copy to clipboard operation
datetimepicker copied to clipboard

Please add props to change theme color of the picker.

Open ajaykumar97 opened this issue 6 years ago • 62 comments

Feature Request

As the default picker theme is "White & green in android and White in iOS". I think there should be an option/prop to change the theme or color of the Date-Picker?

Why it is needed

This feature is needed so as to match the picker color with the app theme and to make it more useful.

ajaykumar97 avatar Aug 31 '19 11:08 ajaykumar97

+1 would be great!

Can it be done with a JS api only? or is it required to modify android theme files?

slorber avatar Sep 04 '19 11:09 slorber

+1, i realy love if it was implemented

mwss1996 avatar Sep 23 '19 00:09 mwss1996

This color is the main issue why a lot of people don't use this package to be honest

jerryheir avatar Oct 03 '19 22:10 jerryheir

+1

My main issue is not being able to change the gradient of the Android picker, not possible to make it look good on a non-white background.

robertherber avatar Oct 08 '19 16:10 robertherber

Hi, sorry my english is bad but i want to share how i can change theme color of the picker. in android/app/src/main/res/values/styles.xml i put:

  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:datePickerDialogTheme">@style/DialogDatePicker.Theme</item>
    </style>

<style name="DialogDatePicker.Theme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/ocean_green</item>
        <item name="android:textColor">@color/dove_gray</item>
        <item name="android:textColorPrimary">@color/dove_gray</item>
    </style>
  • colorAccent is the color of header of picker and selector
  • textColor is the color of numbers and text buttons
  • textColorPrimary is the color of text of month.

I hope it works for you, regards.

guilleSequeiraWolox avatar Oct 23 '19 16:10 guilleSequeiraWolox

Thanks soooooo much

On Wed, Oct 23, 2019, 5:29 PM guillesequeira [email protected] wrote:

Hi, sorry my english is bad but i want to share how i can change theme color of the picker. in android/app/src/main/res/values/styles.xml i putted:

  • colorAccent is the color of header of calendar and selector
  • textColor is the color of numbers and text buttons
  • extColorPrimary is the color of text of month.

I hope it works for you, regards

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/react-native-community/react-native-datetimepicker/issues/20?email_source=notifications&email_token=AHDHZJY3WWEOKKILM5NTQRDQQB3WRA5CNFSM4ISTNG52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECCBPAQ#issuecomment-545527682, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDHZJ5WWKGP7QURAOSXCMTQQB3WRANCNFSM4ISTNG5Q .

jerryheir avatar Oct 23 '19 18:10 jerryheir

@guilleSequeiraWolox Thanks for the excellent example for how to style it statically. However - being able to set it dynamically is a must if your app supports any kinds of themes (which is a common case in these days of Dark Mode).

robertherber avatar Oct 24 '19 10:10 robertherber

Hi,

Unfortunately it will never be possible to change the color of this picker through a prop. The native widget does not allow so, and even android native developers complain about this.

The only way is through xml. If you want to have support for this,asking here won't help, you'd rather complain to google directly.

slorber avatar Oct 24 '19 11:10 slorber

@slorber I see. Maybe it'd be possible to switch native android themes through this library? Then you'd at least be able to provide a dark and light option to switch between :)

robertherber avatar Oct 25 '19 07:10 robertherber

It should be possible to tell the component what theme name to use if my Android skills aren't totally missing. Then yes, you could pass a theme prop in and (in combo with react-native-appearance to fetch current UI mode) set a dark mode correctly

mikehardy avatar Oct 27 '19 18:10 mikehardy

Yes - any PR to do this would alter these calls: https://github.com/react-native-community/react-native-datetimepicker/blob/master/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogFragment.java#L65

Using this constructor: https://developer.android.com/reference/android/app/DatePickerDialog#DatePickerDialog(android.content.Context,%20int,%20android.app.DatePickerDialog.OnDateSetListener,%20int,%20int,%20int)

To pass in a value that was "somehow passed to Java" (via an API that does not exist yet on the module)

@Swaagie @slorber does that seem like the rough shape of a solution for Android that would work here? It's not great but it seems dictated by the platform

mikehardy avatar Oct 27 '19 18:10 mikehardy

Implementation ideas - for dark mode specifically at least the system already has a named theme for it, so for the "typical" (i.e. "support light and dark mode") use case there's no need to mess with themes even as long as you could pass the theme name in as they do here:

https://www.android-examples.com/change-datepickerdialog-theme-in-android-using-dialogfragment/

But the names themselves have moved across APIs (see update here) https://stackoverflow.com/a/25585029/9910298

mikehardy avatar Oct 27 '19 19:10 mikehardy

Agree, we needs this feature.

teamzz111 avatar Jan 03 '20 17:01 teamzz111

Hi, sorry my english is bad but i want to share how i can change theme color of the picker. in android/app/src/main/res/values/styles.xml i put:

  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:datePickerDialogTheme">@style/DialogDatePicker.Theme</item>
    </style>

<style name="DialogDatePicker.Theme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/ocean_green</item>
        <item name="android:textColor">@color/dove_gray</item>
        <item name="android:textColorPrimary">@color/dove_gray</item>
    </style>
  • colorAccent is the color of header of picker and selector
  • textColor is the color of numbers and text buttons
  • textColorPrimary is the color of text of month.

I hope it works for you, regards.

How to make this happen on expo that not ejected?

bsor-dev avatar Feb 04 '20 09:02 bsor-dev

A bit hacky, but I've managed to make it 'kinda white' using shadow props

<DateTimePicker
          style={{
            shadowColor: '#fff',
            shadowRadius: 0,
            shadowOpacity: 1,
            shadowOffset: { height: 0, width: 0 },
          }}
          mode="time"
          value={valueDate}
          minuteInterval={10}
          onChange={(event, date) => {
            if (date) {
              onChange(convertDateToMinutes(date));
              return;
            }
          }}
        />

image

pie6k avatar Feb 14 '20 21:02 pie6k

@sbycrosz, @vonovak Guys, I've seen you created textColor feature, but it still doesn't work. I use 2.3.0 version. Please take a look a snack - https://snack.expo.io/@nozhenkod/rndatetimepicker-text-color

NozhenkoD avatar Mar 20 '20 16:03 NozhenkoD

@NozhenkoD please open a separate issue, thank you.

vonovak avatar Mar 20 '20 18:03 vonovak

Hi, sorry my english is bad but i want to share how i can change theme color of the picker. in android/app/src/main/res/values/styles.xml i put:

  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:datePickerDialogTheme">@style/DialogDatePicker.Theme</item>
    </style>

<style name="DialogDatePicker.Theme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/ocean_green</item>
        <item name="android:textColor">@color/dove_gray</item>
        <item name="android:textColorPrimary">@color/dove_gray</item>
    </style>
* colorAccent is the color of header of picker and selector

* textColor is the color of numbers and text buttons

* textColorPrimary is the color of text of month.

I hope it works for you, regards.

Tip for the those using the time picker and would like to change the colors. Change android:datePickerDialogTheme to android:timePickerDialogTheme

ws333 avatar Mar 23 '20 18:03 ws333

Hi, sorry my english is bad but i want to share how i can change theme color of the picker. in android/app/src/main/res/values/styles.xml i put:

  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:datePickerDialogTheme">@style/DialogDatePicker.Theme</item>
    </style>

<style name="DialogDatePicker.Theme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/ocean_green</item>
        <item name="android:textColor">@color/dove_gray</item>
        <item name="android:textColorPrimary">@color/dove_gray</item>
    </style>
  • colorAccent is the color of header of picker and selector
  • textColor is the color of numbers and text buttons
  • textColorPrimary is the color of text of month.

I hope it works for you, regards.

Is this solution still working for anyone using [email protected]?

My styles.xml file is as follows:

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:textColor">#000000</item>
        <item name="android:datePickerDialogTheme">@style/DialogDatePicker.Theme</item>
        <item name="android:timePickerDialogTheme">@style/DialogDatePicker.Theme</item>
    </style>

    <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/background_splash</item>
        <item name="android:statusBarColor">@color/beige</item>
        <item name="android:textColor">#000000</item>
    </style>

    <style name="DialogDatePicker.Theme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/blue</item>
        <item name="android:textColor">@color/blue</item>
        <item name="android:textColorPrimary">@color/blue</item>
    </style>
</resources>

But both pickers are still appearing as the default teal and white colours.

jamesl1001 avatar Mar 24 '20 14:03 jamesl1001

with [email protected] above solution not working. still looking for a solution

ChathuraPrabhash avatar Apr 18 '20 09:04 ChathuraPrabhash

On what version is this hack working? I have tried multiple versions and none of them is working for me...

biskis avatar Apr 24 '20 20:04 biskis

Solution with android theme changes is not ok, because in app we have more than 1 theme (dark, white, custom and etc.), that configured inside React Native, not native part. So, for now we can not use this solution, because colors can be different between themes

whalemare avatar Apr 26 '20 03:04 whalemare

Is there any working solution for this?

spidi123q avatar May 07 '20 17:05 spidi123q

Hi, sorry my english is bad but i want to share how i can change theme color of the picker. in android/app/src/main/res/values/styles.xml i put:

  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:datePickerDialogTheme">@style/DialogDatePicker.Theme</item>
    </style>

<style name="DialogDatePicker.Theme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/ocean_green</item>
        <item name="android:textColor">@color/dove_gray</item>
        <item name="android:textColorPrimary">@color/dove_gray</item>
    </style>
* colorAccent is the color of header of picker and selector

* textColor is the color of numbers and text buttons

* textColorPrimary is the color of text of month.

I hope it works for you, regards.

Tip for the those using the time picker and would like to change the colors. Change android:datePickerDialogTheme to android:timePickerDialogTheme

Works for me, thanks!!

Silventino avatar May 12 '20 01:05 Silventino

There are many ideas on this thread we can split them in another issues

  • Feature Request Support Dark Theme
  • Pass theme resource id to DatePickerDialog (Android only)
  • If someone has a problem with textColor open another issue (with a reproducible demo)

Feel free to open this issues.

I can help to implement the feature on Android to pass via prop the themeResId to change the theme of the DatePickerDialog

luancurti avatar May 12 '20 14:05 luancurti

Maybe somebody else is having the same problem as me.

Simply remove display="calendar" from <DateTimePicker> tag.

After that, it worked perfectly. I don't know why if I have display="calendar" the syle is not working anymore

biskis avatar May 12 '20 19:05 biskis

@biskis @Silventino none of the solutions are working for me, can you show all props which is used

spidi123q avatar May 16 '20 19:05 spidi123q

Finally found a solution pass display="calendar" in android/app/src/main/res/values/styles.xml i put:

<style name="CalendarDatePickerDialog" parent="Theme.AppCompat.Light.Dialog">
     <item name="colorAccent">@color/red</item>
     <item name="android:textColor">@color/red</item>
     <item name="android:textColorPrimary">@color/red</item>
 </style>

spidi123q avatar May 16 '20 20:05 spidi123q

Any update on this issue? Is there any permanent way to only show the light datepicker even in iOS dark mode. My datepicker is completely invisible now(background is white). If anyone knows any workaround. Please help.

Thank you

2xSamurai avatar Jun 25 '20 14:06 2xSamurai

Any update on this issue? Is there any permanent way to only show the light datepicker even in iOS dark mode. My datepicker is completely invisible now(background is white). If anyone knows any workaround. Please help.

Thank you

Follow this example #204 @2xSamurai

luancurti avatar Jul 01 '20 00:07 luancurti