react-native-picker / picker

Picker is a cross-platform UI component for selecting an item from a list of options.
MIT License
1.45k stars 273 forks source link

Picker style not working in Android #491

Open ThePlatinum opened 1 year ago

ThePlatinum commented 1 year ago

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @react-native-picker/picker@2.4.8 for the project I'm working on.

The style props does not work.***

Expected behaviour:

Set itemStyle Style to apply to each of the item labels.

Actually behaviour:

The fontSize and fontFamily do not have impacts

Here is the diff that solved my problem, partially and specific to this project:

diff --git a/node_modules/@react-native-picker/picker/js/PickerAndroid.android.js b/node_modules/@react-native-picker/picker/js/PickerAndroid.android.js
index 6ab670b..0e30750 100644
--- a/node_modules/@react-native-picker/picker/js/PickerAndroid.android.js
+++ b/node_modules/@react-native-picker/picker/js/PickerAndroid.android.js
@@ -23,6 +23,7 @@ import AndroidDropdownPickerNativeComponent from './AndroidDropdownPickerNativeC
 const MODE_DROPDOWN = 'dropdown';

 import type {TextStyleProp} from 'StyleSheet';
+import { defaultFontSize } from '../../../../style/global';

 type PickerAndroidProps = $ReadOnly<{|
   children?: React.Node,
@@ -103,11 +104,12 @@ function PickerAndroid(props: PickerAndroidProps, ref: PickerRef): React.Node {
         label,
         enabled,
         style: {
-          ...style,
           color: style.color ? processColor(style.color) : null,
           backgroundColor: style.backgroundColor
             ? processColor(style.backgroundColor)
             : null,
+          fontSize: defaultFontSize, // Resolves to a number
+          ...style,
         },
       };
     });

This issue body was partially generated by patch-package.