Skip to content

Commit 91f8276

Browse files
authored
Merge pull request #534 from hossein-zare/dev-5.x
v5.4.0
2 parents 6723cd6 + b3c52d4 commit 91f8276

File tree

9 files changed

+202
-74
lines changed

9 files changed

+202
-74
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<img src="https://user-images.githubusercontent.com/56504893/116789839-2c651280-aac6-11eb-99e0-b43b608ed8c7.png" width="270" alt="Screenshot">
77
</p>
88

9+
The example in the screenshots: https://snack.expo.dev/8mHmLfcZf
10+
911
# Documentation
1012
**The documentation has been moved to https://hossein-zare.github.io/react-native-dropdown-picker-website/**
1113

index.d.ts

+52-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
declare module 'react-native-dropdown-picker' {
2-
import type { ComponentType, SetStateAction, Dispatch } from 'react';
2+
import type { Dispatch, PropsWithoutRef } from 'react';
33
import type {
44
FlatListProps,
55
LayoutChangeEvent,
@@ -14,13 +14,16 @@ declare module 'react-native-dropdown-picker' {
1414
ViewStyle,
1515
} from 'react-native';
1616

17+
type SetStateCallback<S> = ((prevState: S) => S);
18+
type SetStateValue<S> = ((prevState: S) => S);
19+
1720
export type ValueType = string | number | boolean;
1821

19-
export type ItemType = {
22+
export type ItemType<T> = {
2023
label?: string;
21-
value?: ValueType;
24+
value?: T;
2225
icon?: () => void;
23-
parent?: ValueType;
26+
parent?: T;
2427
selectable?: boolean;
2528
disabled?: boolean;
2629
testID?: string;
@@ -65,18 +68,23 @@ declare module 'react-native-dropdown-picker' {
6568
| 'FA'
6669
| 'TR'
6770
| 'RU'
68-
| 'ES';
71+
| 'ES'
72+
| 'ID'
73+
| 'IT';
6974

7075
export interface TranslationInterface {
7176
PLACEHOLDER: string;
7277
SEARCH_PLACEHOLDER: string;
73-
SELECTED_ITEMS_COUNT_TEXT: string;
78+
SELECTED_ITEMS_COUNT_TEXT: string | {
79+
[key in (number | "n")]: string;
80+
};
7481
NOTHING_TO_SHOW: string;
7582
}
7683

77-
export interface RenderBadgeItemPropsInterface {
84+
export interface RenderBadgeItemPropsInterface<T> {
7885
label: string;
79-
value: ValueType;
86+
value: T;
87+
props: TouchableOpacityProps;
8088
IconComponent: () => JSX.Element;
8189
textStyle: StyleProp<TextStyle>;
8290
badgeStyle: StyleProp<ViewStyle>;
@@ -85,17 +93,17 @@ declare module 'react-native-dropdown-picker' {
8593
getBadgeColor: (value: string) => string;
8694
getBadgeDotColor: (value: string) => string;
8795
showBadgeDot: boolean;
88-
onPress: (value: ValueType) => void;
96+
onPress: (value: T) => void;
8997
rtl: boolean;
9098
THEME: ThemeType;
9199
}
92100

93-
export interface RenderListItemPropsInterface {
101+
export interface RenderListItemPropsInterface<T> {
94102
rtl: boolean;
95-
item: ItemType;
103+
item: ItemType<T>;
96104
label: string;
97-
value: ValueType;
98-
parent: ValueType;
105+
value: T;
106+
parent: T;
99107
selectable: boolean;
100108
disabled: boolean;
101109
props: ViewProps;
@@ -118,8 +126,8 @@ declare module 'react-native-dropdown-picker' {
118126
containerStyle: StyleProp<ViewStyle>;
119127
labelStyle: StyleProp<TextStyle>;
120128
categorySelectable: boolean;
121-
onPress: () => void;
122-
setPosition: (value: ValueType, y: number) => void;
129+
onPress: (value: T) => void;
130+
setPosition: (value: T, y: number) => void;
123131
theme: ThemeNameType;
124132
THEME: ThemeType;
125133
}
@@ -143,8 +151,8 @@ declare module 'react-native-dropdown-picker' {
143151
export type ThemeNameType = 'DEFAULT' | 'LIGHT' | 'DARK';
144152
export type ThemeType = object;
145153

146-
interface DropDownPickerBaseProps {
147-
items: ItemType[];
154+
interface DropDownPickerBaseProps<T> {
155+
items: ItemType<T>[];
148156
open: boolean;
149157
placeholder?: string;
150158
closeAfterSelecting?: boolean;
@@ -198,8 +206,8 @@ declare module 'react-native-dropdown-picker' {
198206
mode?: ModeType;
199207
itemKey?: string;
200208
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;
203211
itemSeparator?: boolean;
204212
bottomOffset?: number;
205213
badgeColors?: string[] | string;
@@ -229,8 +237,9 @@ declare module 'react-native-dropdown-picker' {
229237
activityIndicatorColor?: string;
230238
props?: TouchableOpacityProps;
231239
itemProps?: TouchableOpacityProps;
240+
badgeProps?: TouchableOpacityProps;
232241
modalProps?: ModalProps;
233-
flatListProps?: Partial<FlatListProps<ItemType>>;
242+
flatListProps?: Partial<FlatListProps<ItemType<T>>>;
234243
scrollViewProps?: ScrollViewProps;
235244
searchTextInputProps?: TextInputProps;
236245
modalTitle?: string;
@@ -239,15 +248,16 @@ declare module 'react-native-dropdown-picker' {
239248
min?: number;
240249
max?: number;
241250
addCustomItem?: boolean;
242-
setOpen: Dispatch<SetStateAction<boolean>>;
243-
setItems?: Dispatch<SetStateAction<any[]>>;
251+
setOpen: Dispatch<SetStateValue<boolean>>;
252+
setItems?: Dispatch<SetStateCallback<any[]>>;
244253
disableBorderRadius?: boolean;
245254
containerProps?: ViewProps;
246255
onLayout?: (e: LayoutChangeEvent) => void;
247256
onPress?: (open: boolean) => void;
248257
onOpen?: () => void;
249258
onClose?: () => void;
250259
onChangeSearchText?: (text: string) => void;
260+
onDirectionChanged?: (direction: DropDownDirectionType) => void;
251261
zIndex?: number;
252262
zIndexInverse?: number;
253263
disableLocalSearch?: boolean;
@@ -256,22 +266,24 @@ declare module 'react-native-dropdown-picker' {
256266
rtl?: boolean;
257267
testID?: string;
258268
closeOnBackPressed?: boolean;
269+
hideSelectedItemIcon?: boolean;
270+
extendableBadgeContainer?: boolean;
259271
}
260272

261-
interface DropDownPickerSingleProps {
273+
interface DropDownPickerSingleProps<T> {
262274
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;
267279
}
268280

269-
interface DropDownPickerMultipleProps {
281+
interface DropDownPickerMultipleProps<T> {
270282
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;
275287
}
276288

277289
interface DropDownPickerInterface {
@@ -297,13 +309,16 @@ declare module 'react-native-dropdown-picker' {
297309
) => void;
298310
}
299311

300-
export type DropDownPickerProps = (
301-
| DropDownPickerSingleProps
302-
| DropDownPickerMultipleProps
312+
export type DropDownPickerProps<T> = (
313+
| DropDownPickerSingleProps<T>
314+
| DropDownPickerMultipleProps<T>
303315
) &
304-
DropDownPickerBaseProps;
316+
DropDownPickerBaseProps<T>;
305317

306-
const DropDownPicker: ComponentType<DropDownPickerProps> &
318+
const DropDownPicker: (<T extends ValueType>(
319+
props: PropsWithoutRef<DropDownPickerProps<T>>,
320+
) => React.ReactElement) &
307321
DropDownPickerInterface;
322+
308323
export default DropDownPicker;
309324
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-dropdown-picker",
3-
"version": "5.3.0",
3+
"version": "5.4.0",
44
"description": "A single / multiple, categorizable, customizable, localizable and searchable item picker (drop-down) component for react native which supports both Android & iOS.",
55
"keywords": [
66
"picker",

0 commit comments

Comments
 (0)