-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Please add props to change theme color of the picker. #20
Comments
+1 would be great! Can it be done with a JS api only? or is it required to modify android theme files? |
+1, i realy love if it was implemented |
This color is the main issue why a lot of people don't use this package to be honest |
+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. |
Hi, sorry my english is bad but i want to share how i can change theme color of the picker.
I hope it works for you, regards. |
This comment was marked as spam.
This comment was marked as spam.
@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). |
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 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 :) |
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 |
Yes - any PR to do this would alter these calls: Using this constructor: 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 |
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) |
Agree, we needs this feature. |
How to make this happen on expo that not ejected? |
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;
}
}}
/> |
@sbycrosz, @vonovak |
@NozhenkoD please open a separate issue, thank you. |
Tip for the those using the time picker and would like to change the colors. |
Is this solution still working for anyone using My
But both pickers are still appearing as the default teal and white colours. |
with [email protected] above solution not working. still looking for a solution |
On what version is this hack working? I have tried multiple versions and none of them is working for me... |
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 |
This comment was marked as duplicate.
This comment was marked as duplicate.
Works for me, thanks!! |
Would like to see this as a prop rather than an xml change. Would be cool to dynamically change this with user based themes within our apps. |
You can try this step, It is worked for me (Android) |
* Add accentColor props for iOs datetimepicker (#20) * Fix rename to accentColor * Fix e2e tests. Scroll to bottom when rendering a date picker. Ensure the date picker is shown. * Fix e2e test. Label Time Picker is used two times in dependency Tree. Find element by type. * Remove code duplications in expample app. * Remove not needed View Tag from example app. * Shorten command with "cd -" Co-authored-by: Vojtech Novak <[email protected]> * Use bigger device for android. * Test: List aviable devices * Use Pixel 4 XL for android e2e Tests * Fix use pixel 4 xl * Revert getInlineTimePickerIOS selection * Revert rename of android.device.debug.binaryPath Co-authored-by: Vojtech Novak <[email protected]> * Fix error in package.json * Fix grammar Co-authored-by: Vojtech Novak <[email protected]> * Fix spelling of iOS Co-authored-by: Vojtech Novak <[email protected]> * Scroll to datepicker only on iOS Co-authored-by: Simon Nagl <[email protected]> Co-authored-by: Vojtech Novak <[email protected]>
I managed to style the DatePicker as a Config Plugin (working with Expo Managed - but of course it requires an updated EAS Build). It could serve as a basis for adding it to android-datepicker-color-config-plugin.js/** @type {import('@expo/config-plugins')} */
const {
AndroidConfig,
withAndroidStyles,
} = require('@expo/config-plugins');
const { assignStylesValue, getAppThemeLightNoActionBarGroup, setStylesItem } = AndroidConfig.Styles;
const DIALOG_PICKER_THEME_NAME = 'DialogDatePicker.Theme';
const TIME_PICKER_THEME_NAME = 'DialogTimePicker.Theme';
const ACCENT_COLOR = '#662C69';
/** @type {import('@expo/config-plugins').ConfigPlugin} */
const withTheme = (config) => withAndroidStyles(config, (config) => {
const dialogDateParent = { name: DIALOG_PICKER_THEME_NAME, parent: 'Theme.AppCompat.Light.Dialog' };
const dialogTimeParent = { name: TIME_PICKER_THEME_NAME, parent: 'Theme.AppCompat.Light.Dialog' };
config.modResults = setStylesItem({
parent: dialogDateParent,
xml: config.modResults,
item: {
$: {
name: 'colorAccent',
},
_: ACCENT_COLOR,
},
});
config.modResults = setStylesItem({
parent: dialogTimeParent,
xml: config.modResults,
item: {
$: {
name: 'colorAccent',
},
_: ACCENT_COLOR,
},
});
config.modResults = assignStylesValue(config.modResults, {
add: true,
parent: getAppThemeLightNoActionBarGroup(),
name: 'android:datePickerDialogTheme',
value: `@style/${DIALOG_PICKER_THEME_NAME}`,
});
config.modResults = assignStylesValue(config.modResults, {
add: true,
parent: getAppThemeLightNoActionBarGroup(),
name: 'android:timePickerDialogTheme',
value: `@style/${TIME_PICKER_THEME_NAME}`,
});
return config;
});
module.exports = withTheme; Add it to your {
"expo": {
"plugins": ["./android-datepicker-color-config-plugin.js"]
}
} BUT for some reason it does not apply the changes to the TimePicker. The resulting styles.xml looks like this: styles.xml<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColor">@android:color/black</item>
<item name="android:editTextStyle">@style/ResetEditText</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:datePickerDialogTheme">@style/DialogDatePicker.Theme</item>
<item name="android:timePickerDialogTheme">@style/DialogTimePicker.Theme</item>
</style>
<style name="ResetEditText" parent="@android:style/Widget.EditText">
<item name="android:padding">0dp</item>
<item name="android:textColorHint">#c8c8c8</item>
<item name="android:textColor">@android:color/black</item>
</style>
<style name="Theme.App.SplashScreen" parent="AppTheme">
<item name="android:windowBackground">@drawable/splashscreen</item>
</style>
<style name="DialogDatePicker.Theme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#662C69</item>
</style>
<style name="DialogTimePicker.Theme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#662C69</item>
</style>
</resources> Can someone figure out why the TimePicker color doesn't take? I think it looks similar to previous examples in this Issue.. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Managed Expo builds/creates native apps on the spot, hence why you don't usually commit those files to the repo, the build commands ensure you have a fresh native project setup every time you run build or delete the native folders generated. This poses a big challenge when it comes to modifying native code in managed Expo. You'd have to go off the trodden path and start version controlling/patching the setup that Expo generates. Unless a pure JS implementation of a datetimepicker is created, or the colors are exposed through the RN bridge API, it'll be hard to dynamically change colors at runtime. |
adding a config plugin based on what @robertherber to this package has created seems like a great idea (hopefully we can figure out how to get it to apply to the time picker too). |
Hi i am having issue on Android 13 Samsung device.Tried the above code in styles.xml but didn't work.
|
Hello everyone. Here's a proposal to address this issue #801, I created a plugin that makes it possible to style both DatePickerDialog and TimePickerDialog. |
it works for me, thank you so much |
Is it so hard to add it as props ? Its several years now that people need this feature and this is the most advertised library. I don't get how unelegant it is to use considering how many people needing it |
"Hi 👋 My name is @Haukez and I have a huge sense of entitlement! I haven't proposed a PR but I sure do wish someone would do it for me so I can use their free work. Also, insults! Cheers" |
@mikehardy why so insecure? who is insulting who? had a rough day ??? |
There are people who self reflect and notice their entitled behavior and there are people who don't 😂🤷 |
Ok you prove to be a social justice warrior |
@Haukez this article spells it out nicely: https://medium.com/hackernoon/i-thought-i-understood-open-source-i-was-wrong-cf54999c097b I am a warrior for open source. And I advocate for people to realize that if they use open source libraries they are the developer of that library. There are no users of open source libraries because that's not how open source works. If you use the library and you need a thing, you need to make that thing or wait quietly until someone else does. Complaining a thing doesn't exist in an open source library is entitled behavior, and there is nothing about it related to social justice. It's about recognizing your place in this open source world. You should think about that. Anyone that needs this feature - before typing up a comment expressing your wish, think about opening up that code editor instead and making the change you want. That's open source, that's how it moves forward. Cheers |
This is how I got it to work with a config plugin in the Expo managed workflow: https://stackoverflow.com/q/77703362/4350421 |
Datetimepicker v7.6.3, React native 0.73.6 This code is working for android
|
Hoping for a future solution, until then, thanks for the suggestions in the thread here, and thanks for all the hard work put into this library @mikehardy - It's contribution like this, to the community, that makes it a joy to create React Native apps. Cheers! |
🎉 This issue has been resolved in version 8.2.0 🎉 If this package helps you, consider sponsoring us! 🚀 |
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.
The text was updated successfully, but these errors were encountered: