Skip to content

Commit 7a8fbda

Browse files
committed
refactor example to use flatlist
1 parent a5d64ad commit 7a8fbda

File tree

4 files changed

+5101
-4718
lines changed

4 files changed

+5101
-4718
lines changed

examples/App.tsx

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
import React, { JSX } from 'react';
2-
import { StyleSheet, View, useColorScheme } from 'react-native';
2+
import { StyleSheet, View, Text, FlatList, useColorScheme } from 'react-native';
33
import { GestureHandlerRootView } from 'react-native-gesture-handler';
4-
import DropDownPickerExample from './example-src-files/example';
5-
6-
enum ExampleComponent {
7-
JavaScriptClassSingleValue,
8-
JavaScriptClassMultiValue,
9-
JavaScriptFunctionSingleValue,
10-
JavaScriptFunctionMultiValue,
11-
TypeScriptClassSingleValue,
12-
TypeScriptClassMultiValue,
13-
TypeScriptFunctionSingleValue,
14-
TypeScriptFunctionMultiValue,
15-
}
4+
import DropDownPickerExample, { ExampleProps } from './example-src-files/example';
165

176
const styles = StyleSheet.create({
187
page: {
@@ -32,67 +21,77 @@ const styles = StyleSheet.create({
3221
flexDirection: 'column',
3322
justifyContent: 'flex-start',
3423
gap: 32
24+
},
25+
exampleCard: {
26+
zIndex:0,
27+
borderRadius: 8,
28+
marginBottom: 48
3529
}
3630
});
3731

32+
const EXAMPLES: ExampleProps[] = [{
33+
title: "Default Example",
34+
description: "This is the default dropdown picker"
35+
},{
36+
title: "Multiple Select",
37+
description: "Multiple select example",
38+
multiple: true
39+
},{
40+
title: "Multiple Select Badge Mode",
41+
description: "Multiple select example - with badges",
42+
multiple: true,
43+
dropdownProps: {mode: "BADGE"},
44+
},{
45+
title: "Autoscroll Example",
46+
description: "This is the default dropdown picker - with autoscroll",
47+
dropdownProps: {autoScroll: true},
48+
},{
49+
title: "Searchable Example",
50+
description: "This is the default dropdown picker - with search",
51+
dropdownProps: {searchable: true},
52+
},{
53+
title: "Multiple Search Example",
54+
description: "This is the default dropdown picker - with search",
55+
multiple: true,
56+
dropdownProps: {searchable: true},
57+
},{
58+
title: "Multiple Search Clear on Select Example",
59+
description: "This is the default dropdown picker - with search",
60+
multiple: true,
61+
dropdownProps: {searchable: true, clearSearchFieldOnSelect: true, mode: "BADGE"},
62+
},{
63+
title: "Modal Example",
64+
description: "This is the default dropdown picker - with search",
65+
multiple: true,
66+
dropdownProps: {listMode: "MODAL"}
67+
}]
68+
3869
export default function App(): JSX.Element {
3970
const colorScheme = useColorScheme();
4071
const backgroundColor = colorScheme === 'dark' ? '#222' : '#fff';
4172

73+
const renderItem = ({ item }: { item: ExampleProps }) => (
74+
<View style={styles.exampleCard} key={item.title}>
75+
<DropDownPickerExample
76+
{...item}
77+
/>
78+
</View>
79+
);
80+
4281
return (
4382
<GestureHandlerRootView style={{ flex: 1 }}>
4483
<View style={{
4584
...styles.page,
4685
backgroundColor,
4786
}}>
48-
<View style={styles.container}>
49-
<View style={styles.examplesContainer}>
50-
<DropDownPickerExample
51-
title="Default Example"
52-
description="This is the default dropdown picker"
53-
/>
54-
55-
<DropDownPickerExample
56-
title="Multiple Select"
57-
description="Multiple select example"
58-
multiple
59-
/>
60-
61-
<DropDownPickerExample
62-
title="Multiple Select Badge Mode"
63-
description="Multiple select example - with badges"
64-
multiple
65-
dropdownProps={{mode: "BADGE"}}
66-
/>
67-
68-
<DropDownPickerExample
69-
title="Autoscroll Example"
70-
description="This is the default dropdown picker - with autoscroll"
71-
dropdownProps={{autoScroll: true}}
72-
/>
73-
74-
75-
<DropDownPickerExample
76-
title="Searchable Example"
77-
description="This is the default dropdown picker - with search"
78-
dropdownProps={{searchable: true}}
79-
/>
80-
81-
<DropDownPickerExample
82-
title="Multiple Search Example"
83-
description="This is the default dropdown picker - with search"
84-
multiple
85-
dropdownProps={{searchable: true}}
86-
/>
87-
88-
<DropDownPickerExample
89-
title="Multiple Search Clear on Select Example"
90-
description="This is the default dropdown picker - with search"
91-
multiple
92-
dropdownProps={{searchable: true, clearSearchFieldOnSelect: true, mode: "BADGE"}}
93-
/>
94-
</View>
95-
</View>
87+
<FlatList
88+
data={EXAMPLES}
89+
style={{zIndex: 0}}
90+
keyExtractor={(example: ExampleProps) => example.title}
91+
renderItem={renderItem}
92+
contentContainerStyle={styles.container}
93+
showsVerticalScrollIndicator={false}
94+
/>
9695
</View>
9796
</GestureHandlerRootView>
9897
);

examples/example-src-files/example.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, JSX } from 'react';
22
import { StyleSheet, Button, Text, View, useColorScheme } from 'react-native';
33
import DropDownPicker, { ItemType,DropDownPickerProps } from 'react-native-dropdown-picker';
44

5-
type ExampleProps = {
5+
export type ExampleProps = {
66
multiple?: boolean;
77
title: string;
88
description?: string;
@@ -36,6 +36,11 @@ const styles = StyleSheet.create({
3636
},
3737
description: {
3838
fontSize: 12,
39+
marginBottom: 16
40+
},
41+
body: {
42+
fontSize: 12,
43+
marginBottom: 72,
3944
},
4045
exampleContainer: {
4146
display: 'flex',
@@ -111,16 +116,14 @@ export default function DropDownPickerExample({
111116
{...dropdownProps}
112117
/>
113118
)}
114-
<View>
119+
<View style={{...styles.body}}>
115120
<Text style={{...styles.description, color}}>
116121
{multiple ? 'Fruits currently are: ' : 'Fruit currently is: '}
117122
{multiple
118123
? JSON.stringify(multiValue)
119124
: JSON.stringify(singleValue)}
120125
</Text>
121-
</View>
122126

123-
<View>
124127
<Button
125128
title={multiple ? 'Clear fruits' : 'Clear fruit'}
126129
onPress={(): void => {

0 commit comments

Comments
 (0)