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

Picker 2.6+ transforms numeric values to strings #538

Open
swrobel opened this issue Dec 27, 2023 · 7 comments
Open

Picker 2.6+ transforms numeric values to strings #538

swrobel opened this issue Dec 27, 2023 · 7 comments

Comments

@swrobel
Copy link

swrobel commented Dec 27, 2023

If I have a Picker Item with value={10}, using 2.5.1, the value will be set to 10 when I select that, but starting with 2.6.0, it will be set to "10" which is a substantial breaking change.

@stevenpal
Copy link

Experiencing the same issue with 2.6.1 on iOS (Android works as expected). Reverting to 2.5.1 for now, which appears compatible with Expo 50 so far (for the Expo users out there).

@elkinjosetm
Copy link

We are having the same issue in our project, we'll need to revert until a fix is released

@swrobel
Copy link
Author

swrobel commented Mar 26, 2024

@WoLewicki since you worked on the PR that seems to have introduced this bug, could you take a look at this?

@WoLewicki
Copy link
Contributor

Yeah, I can see that, as mentioned here: https://github.com/react-native-picker/picker/pull/456/files/624af21c3f1fa6212d5f13dfb7f21de8e43ba3af#r1526543524, this makes the value always a string. It's like this due to codegen not accepting mixed types 😞 We would need to change this type to UnsafeMixed and parse it correctly on the native side. It is doable, but right now I have little time to do it unfortunately. I took the same approach here: software-mansion/react-native-svg#2238 if someone is willing to contribute. If not, I'll try to find an hour to do it.

@swrobel
Copy link
Author

swrobel commented Nov 22, 2024

@WoLewicki is there any chance you could take another look at this?

@andrejpavlovic
Copy link

I added this patch to my repo to make sure I'm always passing in strings.

react-native-picker-select+9.3.1.patch

diff --git a/node_modules/react-native-picker-select/index.d.ts b/node_modules/react-native-picker-select/index.d.ts
index cac5c68..38aa318 100644
--- a/node_modules/react-native-picker-select/index.d.ts
+++ b/node_modules/react-native-picker-select/index.d.ts
@@ -11,7 +11,7 @@ import { PickerProps } from '@react-native-picker/picker/typings/Picker';
 
 export interface Item {
     label: string;
-    value: any;
+    value: string;
     key?: string | number;
     color?: string;
     testID?: string;
@@ -68,9 +68,9 @@ type CustomTouchableWrapperProps = Omit<TouchableOpacityProps, 'onPress'>;
 // 'testID' and 'activeOpacity' are also used, but can be overwritten safely
 
 export interface PickerSelectProps {
-    onValueChange: (value: any, index: number) => void;
+    onValueChange: (value: string, index: number) => void;
     items: Item[];
-    value?: any;
+    value?: string;
     placeholder?: Item | {};
     disabled?: boolean;
     itemKey?: string | number;

@WoLewicki
Copy link
Contributor

Can you check if #600 fixes the issue? Also, does it happen on Android too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants