-
-
Notifications
You must be signed in to change notification settings - Fork 393
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
base: master
Are you sure you want to change the base?
feat: create expo plugin to customize native style #801
Conversation
e23c9d1
to
f9f118c
Compare
colorAccent: {attrName: 'colorAccent', colorName: 'datePicker_colorAccent'}, | ||
colorControlActivated: { | ||
attrName: 'colorControlActivated', | ||
colorName: 'datePicker_colorControlActivated', |
There was a problem hiding this comment.
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.
} | ||
``` | ||
|
||
Due to a limitation in the way the plugin system works, works, it's not possible to write a custom styles.xml for the values-night, so when customizing a specific property, you must declare a value for both the `light` and `dark` themes. If you don't, the plugin will not work and the following error will be thrown: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to a limitation in the way the plugin system works, works, it's not possible to write a custom styles.xml for the values-night, so when customizing a specific property, you must declare a value for both the `light` and `dark` themes. If you don't, the plugin will not work and the following error will be thrown: | |
Due to a limitation in the way the plugin system works, it's not possible to write a custom styles.xml for the values-night, so when customizing a specific property, you must declare a value for both the `light` and `dark` themes. If you don't, the plugin will not work and the following error will be thrown: |
const setAndroidDatePickerStyles = ( | ||
styles: ResourceXML, | ||
{light, dark}: DatePickerTheme, | ||
): ResourceXML => { | ||
styles = Object.keys({...light, ...dark}).reduce((acc, attr) => { | ||
const {attrName, colorName} = | ||
DATE_PICKER_ALLOWED_ATTRIBUTES[attr as keyof DatePickerProps]; | ||
|
||
return assignStylesValue(acc, { | ||
add: true, | ||
parent: { | ||
name: DATE_PICKER_STYLE_NAME, | ||
parent: 'Theme.AppCompat.Light.Dialog', | ||
}, | ||
name: attrName, | ||
value: `@color/${colorName}`, | ||
}); | ||
}, styles); | ||
|
||
styles = assignStylesValue(styles, { | ||
add: true, | ||
parent: getAppThemeLightNoActionBarGroup(), | ||
name: DATE_PICKER_THEME_ATTRIBUTE, | ||
value: `@style/${DATE_PICKER_STYLE_NAME}`, | ||
}); | ||
|
||
return styles; | ||
}; | ||
|
||
const setAndroidTimePickerStyles = ( | ||
styles: ResourceXML, | ||
{light, dark}: TimePickerTheme, | ||
): ResourceXML => { | ||
styles = Object.keys({...light, ...dark}).reduce((acc, attr) => { | ||
const {attrName, colorName} = | ||
TIME_PICKER_ALLOWED_ATTRIBUTES[attr as keyof TimePickerProps]; | ||
|
||
return assignStylesValue(acc, { | ||
add: true, | ||
parent: { | ||
name: TIME_PICKER_STYLE_NAME, | ||
parent: 'android:Widget.Material.Light.TimePicker', | ||
}, | ||
name: attrName, | ||
value: `@color/${colorName}`, | ||
}); | ||
}, styles); | ||
|
||
styles = assignStylesValue(styles, { | ||
add: true, | ||
parent: getAppThemeLightNoActionBarGroup(), | ||
name: TIME_PICKER_THEME_ATTRIBUTE, | ||
value: `@style/${TIME_PICKER_STYLE_NAME}`, | ||
}); | ||
|
||
return styles; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a generic method to dedupe these two functions? They're doing the same thing with different arguments.
I guess we'll have to wait until like 2025. |
@brunohkbx anything we can do to help move this forward? |
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
styles.xml
Entries added in the style
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
New style entries added
colors.xml
values-night/colors.xml
What's required for testing (prerequisites)?
expo init
expo install @react-native-community/datetimepicker
What are the steps to reproduce (after prerequisites)?
You should see the new styles applied to either a RNDateTimePicker with
mode="date"
ormode="time"
Compatibility
Checklist
README.md
example/App.js
)