1
1
declare module 'react-native-dropdown-picker' {
2
- import type { ComponentType , SetStateAction , Dispatch } from 'react' ;
2
+ import type { Dispatch , PropsWithoutRef } from 'react' ;
3
3
import type {
4
4
FlatListProps ,
5
5
LayoutChangeEvent ,
@@ -14,13 +14,16 @@ declare module 'react-native-dropdown-picker' {
14
14
ViewStyle ,
15
15
} from 'react-native' ;
16
16
17
+ type SetStateCallback < S > = ( ( prevState : S ) => S ) ;
18
+ type SetStateValue < S > = ( ( prevState : S ) => S ) ;
19
+
17
20
export type ValueType = string | number | boolean ;
18
21
19
- export type ItemType = {
22
+ export type ItemType < T > = {
20
23
label ?: string ;
21
- value ?: ValueType ;
24
+ value ?: T ;
22
25
icon ?: ( ) => void ;
23
- parent ?: ValueType ;
26
+ parent ?: T ;
24
27
selectable ?: boolean ;
25
28
disabled ?: boolean ;
26
29
testID ?: string ;
@@ -65,18 +68,23 @@ declare module 'react-native-dropdown-picker' {
65
68
| 'FA'
66
69
| 'TR'
67
70
| 'RU'
68
- | 'ES' ;
71
+ | 'ES'
72
+ | 'ID'
73
+ | 'IT' ;
69
74
70
75
export interface TranslationInterface {
71
76
PLACEHOLDER : string ;
72
77
SEARCH_PLACEHOLDER : string ;
73
- SELECTED_ITEMS_COUNT_TEXT : string ;
78
+ SELECTED_ITEMS_COUNT_TEXT : string | {
79
+ [ key in ( number | "n" ) ] : string ;
80
+ } ;
74
81
NOTHING_TO_SHOW : string ;
75
82
}
76
83
77
- export interface RenderBadgeItemPropsInterface {
84
+ export interface RenderBadgeItemPropsInterface < T > {
78
85
label : string ;
79
- value : ValueType ;
86
+ value : T ;
87
+ props : TouchableOpacityProps ;
80
88
IconComponent : ( ) => JSX . Element ;
81
89
textStyle : StyleProp < TextStyle > ;
82
90
badgeStyle : StyleProp < ViewStyle > ;
@@ -85,17 +93,17 @@ declare module 'react-native-dropdown-picker' {
85
93
getBadgeColor : ( value : string ) => string ;
86
94
getBadgeDotColor : ( value : string ) => string ;
87
95
showBadgeDot : boolean ;
88
- onPress : ( value : ValueType ) => void ;
96
+ onPress : ( value : T ) => void ;
89
97
rtl : boolean ;
90
98
THEME : ThemeType ;
91
99
}
92
100
93
- export interface RenderListItemPropsInterface {
101
+ export interface RenderListItemPropsInterface < T > {
94
102
rtl : boolean ;
95
- item : ItemType ;
103
+ item : ItemType < T > ;
96
104
label : string ;
97
- value : ValueType ;
98
- parent : ValueType ;
105
+ value : T ;
106
+ parent : T ;
99
107
selectable : boolean ;
100
108
disabled : boolean ;
101
109
props : ViewProps ;
@@ -118,8 +126,8 @@ declare module 'react-native-dropdown-picker' {
118
126
containerStyle : StyleProp < ViewStyle > ;
119
127
labelStyle : StyleProp < TextStyle > ;
120
128
categorySelectable : boolean ;
121
- onPress : ( ) => void ;
122
- setPosition : ( value : ValueType , y : number ) => void ;
129
+ onPress : ( value : T ) => void ;
130
+ setPosition : ( value : T , y : number ) => void ;
123
131
theme : ThemeNameType ;
124
132
THEME : ThemeType ;
125
133
}
@@ -143,8 +151,8 @@ declare module 'react-native-dropdown-picker' {
143
151
export type ThemeNameType = 'DEFAULT' | 'LIGHT' | 'DARK' ;
144
152
export type ThemeType = object ;
145
153
146
- interface DropDownPickerBaseProps {
147
- items : ItemType [ ] ;
154
+ interface DropDownPickerBaseProps < T > {
155
+ items : ItemType < T > [ ] ;
148
156
open : boolean ;
149
157
placeholder ?: string ;
150
158
closeAfterSelecting ?: boolean ;
@@ -198,8 +206,8 @@ declare module 'react-native-dropdown-picker' {
198
206
mode ?: ModeType ;
199
207
itemKey ?: string ;
200
208
maxHeight ?: number ;
201
- renderBadgeItem ?: ( props : RenderBadgeItemPropsInterface ) => JSX . Element ;
202
- renderListItem ?: ( props : RenderListItemPropsInterface ) => JSX . Element ;
209
+ renderBadgeItem ?: ( props : RenderBadgeItemPropsInterface < T > ) => JSX . Element ;
210
+ renderListItem ?: ( props : RenderListItemPropsInterface < T > ) => JSX . Element ;
203
211
itemSeparator ?: boolean ;
204
212
bottomOffset ?: number ;
205
213
badgeColors ?: string [ ] | string ;
@@ -229,8 +237,9 @@ declare module 'react-native-dropdown-picker' {
229
237
activityIndicatorColor ?: string ;
230
238
props ?: TouchableOpacityProps ;
231
239
itemProps ?: TouchableOpacityProps ;
240
+ badgeProps ?: TouchableOpacityProps ;
232
241
modalProps ?: ModalProps ;
233
- flatListProps ?: Partial < FlatListProps < ItemType > > ;
242
+ flatListProps ?: Partial < FlatListProps < ItemType < T > > > ;
234
243
scrollViewProps ?: ScrollViewProps ;
235
244
searchTextInputProps ?: TextInputProps ;
236
245
modalTitle ?: string ;
@@ -239,15 +248,16 @@ declare module 'react-native-dropdown-picker' {
239
248
min ?: number ;
240
249
max ?: number ;
241
250
addCustomItem ?: boolean ;
242
- setOpen : Dispatch < SetStateAction < boolean > > ;
243
- setItems ?: Dispatch < SetStateAction < any [ ] > > ;
251
+ setOpen : Dispatch < SetStateValue < boolean > > ;
252
+ setItems ?: Dispatch < SetStateCallback < any [ ] > > ;
244
253
disableBorderRadius ?: boolean ;
245
254
containerProps ?: ViewProps ;
246
255
onLayout ?: ( e : LayoutChangeEvent ) => void ;
247
256
onPress ?: ( open : boolean ) => void ;
248
257
onOpen ?: ( ) => void ;
249
258
onClose ?: ( ) => void ;
250
259
onChangeSearchText ?: ( text : string ) => void ;
260
+ onDirectionChanged ?: ( direction : DropDownDirectionType ) => void ;
251
261
zIndex ?: number ;
252
262
zIndexInverse ?: number ;
253
263
disableLocalSearch ?: boolean ;
@@ -256,22 +266,24 @@ declare module 'react-native-dropdown-picker' {
256
266
rtl ?: boolean ;
257
267
testID ?: string ;
258
268
closeOnBackPressed ?: boolean ;
269
+ hideSelectedItemIcon ?: boolean ;
270
+ extendableBadgeContainer ?: boolean ;
259
271
}
260
272
261
- interface DropDownPickerSingleProps {
273
+ interface DropDownPickerSingleProps < T > {
262
274
multiple ?: false ;
263
- onChangeValue ?: ( value : ValueType | null ) => void ;
264
- onSelectItem ?: ( item : ItemType ) => void ;
265
- setValue : Dispatch < SetStateAction < ValueType | null > > ;
266
- value : ValueType | null ;
275
+ onChangeValue ?: ( value : T | null ) => void ;
276
+ onSelectItem ?: ( item : ItemType < T > ) => void ;
277
+ setValue : Dispatch < SetStateCallback < T | null | any > > ;
278
+ value : T | null ;
267
279
}
268
280
269
- interface DropDownPickerMultipleProps {
281
+ interface DropDownPickerMultipleProps < T > {
270
282
multiple : true ;
271
- onChangeValue ?: ( value : ValueType [ ] | null ) => void ;
272
- onSelectItem ?: ( items : ItemType [ ] ) => void ;
273
- setValue : Dispatch < SetStateAction < ValueType [ ] | null > > ;
274
- value : ValueType [ ] | null ;
283
+ onChangeValue ?: ( value : T [ ] | null ) => void ;
284
+ onSelectItem ?: ( items : ItemType < T > [ ] ) => void ;
285
+ setValue : Dispatch < SetStateCallback < T [ ] | null | any > > ;
286
+ value : T [ ] | null ;
275
287
}
276
288
277
289
interface DropDownPickerInterface {
@@ -297,13 +309,16 @@ declare module 'react-native-dropdown-picker' {
297
309
) => void ;
298
310
}
299
311
300
- export type DropDownPickerProps = (
301
- | DropDownPickerSingleProps
302
- | DropDownPickerMultipleProps
312
+ export type DropDownPickerProps < T > = (
313
+ | DropDownPickerSingleProps < T >
314
+ | DropDownPickerMultipleProps < T >
303
315
) &
304
- DropDownPickerBaseProps ;
316
+ DropDownPickerBaseProps < T > ;
305
317
306
- const DropDownPicker : ComponentType < DropDownPickerProps > &
318
+ const DropDownPicker : ( < T extends ValueType > (
319
+ props : PropsWithoutRef < DropDownPickerProps < T > > ,
320
+ ) => React . ReactElement ) &
307
321
DropDownPickerInterface ;
322
+
308
323
export default DropDownPicker ;
309
324
}
0 commit comments