secullum-react-native-ui 4.16.1 → 4.16.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/DropDown.d.ts +16 -12
- package/lib/components/DropDown.js +17 -4
- package/package.json +1 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { IconProps } from 'react-native-vector-icons/Icon';
|
|
3
3
|
import { StyleProp, ViewStyle, TextStyle } from 'react-native';
|
|
4
|
+
declare type DropDownItemData = {
|
|
5
|
+
label: string;
|
|
6
|
+
value: any;
|
|
7
|
+
icon?: string;
|
|
8
|
+
nativeID?: string;
|
|
9
|
+
};
|
|
4
10
|
export interface DropDownProperties {
|
|
5
11
|
label?: string;
|
|
6
|
-
items:
|
|
7
|
-
label: string;
|
|
8
|
-
value: any;
|
|
9
|
-
icon?: string;
|
|
10
|
-
nativeID?: string;
|
|
11
|
-
}>;
|
|
12
|
+
items: DropDownItemData[];
|
|
12
13
|
value: any | null;
|
|
13
14
|
onChange: (value: any) => void;
|
|
14
15
|
onPress?: () => void | boolean | Promise<void> | Promise<boolean>;
|
|
@@ -23,11 +24,17 @@ export interface DropDownProperties {
|
|
|
23
24
|
icon?: string | undefined;
|
|
24
25
|
arrowColor?: string | undefined;
|
|
25
26
|
searchable?: SearchableProps;
|
|
27
|
+
virtualized?: true | VirtualizedProps | null;
|
|
26
28
|
}
|
|
27
29
|
export interface SearchableProps {
|
|
28
30
|
placeHolder: string;
|
|
29
31
|
minItemsToSearch?: number;
|
|
30
32
|
}
|
|
33
|
+
export interface VirtualizedProps {
|
|
34
|
+
initialNumToRender?: number;
|
|
35
|
+
maxToRenderPerBatch?: number;
|
|
36
|
+
windowSize?: number;
|
|
37
|
+
}
|
|
31
38
|
export interface DropDownState {
|
|
32
39
|
modalOpen: boolean;
|
|
33
40
|
searchText: string;
|
|
@@ -35,14 +42,11 @@ export interface DropDownState {
|
|
|
35
42
|
export declare class DropDown extends React.Component<DropDownProperties, DropDownState> {
|
|
36
43
|
state: DropDownState;
|
|
37
44
|
handleItemPress: (value: any) => void;
|
|
38
|
-
filterItems: () =>
|
|
39
|
-
label: string;
|
|
40
|
-
value: any;
|
|
41
|
-
icon?: string | undefined;
|
|
42
|
-
nativeID?: string | undefined;
|
|
43
|
-
}[];
|
|
45
|
+
filterItems: () => DropDownItemData[];
|
|
44
46
|
shouldDisplaySearchField: () => boolean | undefined;
|
|
45
47
|
renderClosedDropDown: (item: any, inputStyle: any) => JSX.Element | null;
|
|
46
48
|
getStyles: () => any;
|
|
49
|
+
renderItemsList: (filteredItems: DropDownItemData[]) => JSX.Element;
|
|
47
50
|
render(): JSX.Element;
|
|
48
51
|
}
|
|
52
|
+
export {};
|
|
@@ -93,6 +93,11 @@ class DropDownItem extends React.PureComponent {
|
|
|
93
93
|
} }, this.renderOpenDropDownItem()));
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
+
const DEFAULT_VIRTUALIZED = {
|
|
97
|
+
initialNumToRender: 20,
|
|
98
|
+
maxToRenderPerBatch: 30,
|
|
99
|
+
windowSize: 10
|
|
100
|
+
};
|
|
96
101
|
class DropDown extends React.Component {
|
|
97
102
|
constructor() {
|
|
98
103
|
super(...arguments);
|
|
@@ -287,10 +292,20 @@ class DropDown extends React.Component {
|
|
|
287
292
|
});
|
|
288
293
|
return styles;
|
|
289
294
|
};
|
|
295
|
+
this.renderItemsList = (filteredItems) => {
|
|
296
|
+
const { iconComponent, virtualized } = this.props;
|
|
297
|
+
const renderItem = ({ item, index }) => (React.createElement(DropDownItem, { nativeID: item.nativeID, first: index === 0, last: index === filteredItems.length - 1, label: item.label, value: item.value, onPress: this.handleItemPress, icon: item.icon, iconComponent: iconComponent }));
|
|
298
|
+
if (virtualized == null) {
|
|
299
|
+
return (React.createElement(react_native_1.FlatList, { data: filteredItems, initialNumToRender: filteredItems.length, keyExtractor: item => item.value.toString(), renderItem: renderItem }));
|
|
300
|
+
}
|
|
301
|
+
const virtualizedProps = virtualized === true
|
|
302
|
+
? Object.assign({}, DEFAULT_VIRTUALIZED) : Object.assign(Object.assign({}, DEFAULT_VIRTUALIZED), virtualized);
|
|
303
|
+
return (React.createElement(react_native_1.VirtualizedList, { getItem: (_, index) => filteredItems[index], getItemCount: () => filteredItems.length, keyExtractor: item => item.value.toString(), renderItem: renderItem, initialNumToRender: virtualizedProps.initialNumToRender, maxToRenderPerBatch: virtualizedProps.maxToRenderPerBatch, windowSize: virtualizedProps.windowSize }));
|
|
304
|
+
};
|
|
290
305
|
}
|
|
291
306
|
render() {
|
|
292
307
|
const { modalOpen, searchText } = this.state;
|
|
293
|
-
const { label, items, value, emptyMessage, style, disabledStyle, disabled, labelStyle, inputStyle,
|
|
308
|
+
const { label, items, value, emptyMessage, style, disabledStyle, disabled, labelStyle, inputStyle, nativeID, onPress, icon, searchable } = this.props;
|
|
294
309
|
const selectedItem = items.find(x => x.value === value);
|
|
295
310
|
const styles = this.getStyles();
|
|
296
311
|
const theme = (0, theme_1.getTheme)();
|
|
@@ -328,9 +343,7 @@ class DropDown extends React.Component {
|
|
|
328
343
|
React.createElement(react_native_1.View, { style: styles.inputWrapper },
|
|
329
344
|
React.createElement(react_native_1.TextInput, { nativeID: nativeID + '-text-search', style: styles.searchInput, value: searchText, placeholder: searchable && searchable.placeHolder, onChangeText: text => this.setState({ searchText: text }) }),
|
|
330
345
|
React.createElement(FontAwesome_1.default, { name: "search", size: 16, color: "gray", style: styles.searchIcon })))),
|
|
331
|
-
filteredItems.length > 0 ? (React.createElement(react_native_1.
|
|
332
|
-
return (React.createElement(DropDownItem, { nativeID: item.nativeID, first: index === 0, last: index === filteredItems.length - 1, label: item.label, value: item.value, onPress: this.handleItemPress, icon: item.icon, iconComponent: iconComponent }));
|
|
333
|
-
} })) : (React.createElement(react_native_1.View, { style: styles.emptyMessageContainer },
|
|
346
|
+
filteredItems.length > 0 ? (this.renderItemsList(filteredItems)) : (React.createElement(react_native_1.View, { style: styles.emptyMessageContainer },
|
|
334
347
|
React.createElement(FontAwesome_1.default, { name: "warning", color: theme.warningColor, size: 24 }),
|
|
335
348
|
React.createElement(react_native_1.Text, { style: styles.modalItem }, emptyMessage)))))))));
|
|
336
349
|
}
|