hossein-zare / react-native-dropdown-picker

A single / multiple, categorizable, customizable, localizable and searchable item picker (drop-down) component for react native which supports both Android & iOS.
https://hossein-zare.github.io/react-native-dropdown-picker-website/
MIT License
992 stars 296 forks source link

Hi admin i want property method addition onPressItemCustom #494

Closed khuongsatou closed 2 years ago

khuongsatou commented 2 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

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

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-dropdown-picker/index.d.ts b/node_modules/react-native-dropdown-picker/index.d.ts
index 7b64898..0247335 100644
--- a/node_modules/react-native-dropdown-picker/index.d.ts
+++ b/node_modules/react-native-dropdown-picker/index.d.ts
@@ -256,6 +256,7 @@ declare module 'react-native-dropdown-picker' {
     rtl?: boolean;
     testID?: string;
     closeOnBackPressed?: boolean;
+    onPressItemCustom:(value?:any)=>void;
   }

   interface DropDownPickerSingleProps {
diff --git a/node_modules/react-native-dropdown-picker/src/components/Picker.js b/node_modules/react-native-dropdown-picker/src/components/Picker.js
index a154d88..1b9b435 100644
--- a/node_modules/react-native-dropdown-picker/src/components/Picker.js
+++ b/node_modules/react-native-dropdown-picker/src/components/Picker.js
@@ -155,7 +155,8 @@ function Picker({
     theme = THEMES.DEFAULT,
     testID,
     closeOnBackPressed = false,
-    onSelectItem = (item) => {}
+    onSelectItem = (item) => {},
+    onPressItemCustom=(item)=>{},
 }) {
     const [necessaryItems, setNecessaryItems] = useState([]);
     const [searchText, setSearchText] = useState('');
@@ -1192,6 +1193,9 @@ function Picker({
      * onPress item.
      */
     const onPressItem = useCallback((item, customItem = false) => {
+        if(Boolean(onPressItemCustom)){
+            onPressItemCustom(item)
+        }
         if (customItem !== false) {
             item.custom = false;
             setItems(state => [...state, item]);

This issue body was partially generated by patch-package.

hossein-zare commented 2 years ago

Hi,

Why don't you use onSelectItem ?