Skip to content

Commit 8ac4a65

Browse files
committed
refactor: replace old exmples
1 parent b970cd0 commit 8ac4a65

File tree

1 file changed

+38
-93
lines changed

1 file changed

+38
-93
lines changed

examples/App.tsx

Lines changed: 38 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import JavascriptFunctionExample from './example-src-files/javascript-function-e
66
import TypescriptClassExample from './example-src-files/typescript-class-example';
77
import TypescriptFunctionExample from './example-src-files/typescript-function-example';
88
import { GestureHandlerRootView } from 'react-native-gesture-handler';
9+
import DropDownPickerExample from './example-src-files/example';
910

1011
enum ExampleComponent {
1112
JavaScriptClassSingleValue,
@@ -21,90 +22,25 @@ enum ExampleComponent {
2122
const styles = StyleSheet.create({
2223
page: {
2324
flex: 1,
24-
justifyContent: 'center',
25-
alignItems: 'center',
26-
width: '100%',
27-
height: '100%',
2825
},
2926
container: {
3027
flexDirection: 'column',
3128
margin: 'auto',
32-
marginTop: 20,
29+
marginTop: 64,
30+
marginBottom: 64,
3331
padding: 3,
34-
maxWidth: 400,
32+
maxWidth: 600,
33+
minWidth: 400
3534
},
36-
});
37-
38-
const EXAMPLE_COMPONENT_ITEMS: Array<ItemType<ExampleComponent>> = [
39-
{
40-
label: 'JavaScript; class component; single-item',
41-
value: ExampleComponent.JavaScriptClassSingleValue,
42-
},
43-
{
44-
label: 'JavaScript; class component; multiple-item',
45-
value: ExampleComponent.JavaScriptClassMultiValue,
46-
},
47-
{
48-
label: 'JavaScript; function component; single-item',
49-
value: ExampleComponent.JavaScriptFunctionSingleValue,
50-
},
51-
{
52-
label: 'JavaScript; function component; multiple-item',
53-
value: ExampleComponent.JavaScriptFunctionMultiValue,
54-
},
55-
{
56-
label: 'TypeScript; class component; single-item',
57-
value: ExampleComponent.TypeScriptClassSingleValue,
58-
},
59-
{
60-
label: 'TypeScript; class component; multiple-item',
61-
value: ExampleComponent.TypeScriptClassMultiValue,
62-
},
63-
{
64-
label: 'TypeScript; function component; single-item',
65-
value: ExampleComponent.TypeScriptFunctionSingleValue,
66-
},
67-
{
68-
label: 'TypeScript; function component; multiple-item',
69-
value: ExampleComponent.TypeScriptFunctionMultiValue,
70-
},
71-
];
72-
73-
const getExample = (egComponent: ExampleComponent): JSX.Element => {
74-
switch (egComponent) {
75-
case ExampleComponent.JavaScriptClassSingleValue:
76-
return <JavascriptClassExample multiple={false} />;
77-
case ExampleComponent.JavaScriptClassMultiValue:
78-
return <JavascriptClassExample multiple />;
79-
case ExampleComponent.JavaScriptFunctionSingleValue:
80-
return <JavascriptFunctionExample multiple={false} />;
81-
case ExampleComponent.JavaScriptFunctionMultiValue:
82-
return <JavascriptFunctionExample multiple />;
83-
case ExampleComponent.TypeScriptClassSingleValue:
84-
return <TypescriptClassExample multiple={false} />;
85-
case ExampleComponent.TypeScriptClassMultiValue:
86-
return <TypescriptClassExample multiple />;
87-
case ExampleComponent.TypeScriptFunctionSingleValue:
88-
return <TypescriptFunctionExample multiple={false} />;
89-
case ExampleComponent.TypeScriptFunctionMultiValue:
90-
return <TypescriptFunctionExample multiple />;
91-
default:
92-
throw new Error(
93-
"couldn't match example component in getExample() in App.tsx. egComponent was: ",
94-
egComponent,
95-
);
35+
examplesContainer: {
36+
display: 'flex',
37+
flexDirection: 'column',
38+
justifyContent: 'flex-start',
39+
gap: 32
9640
}
97-
};
41+
});
9842

9943
export default function App(): JSX.Element {
100-
const [currentExample, setCurrentExample] = useState<ExampleComponent>(
101-
ExampleComponent.JavaScriptClassSingleValue
102-
);
103-
const [examplePickerOpen, setOpen] = useState<boolean>(false);
104-
const [exampleComponents] = useState<Array<ItemType<ExampleComponent>>>(
105-
EXAMPLE_COMPONENT_ITEMS
106-
);
107-
10844
const colorScheme = useColorScheme();
10945
const backgroundColor = colorScheme === 'dark' ? '#222' : '#fff';
11046

@@ -115,28 +51,37 @@ export default function App(): JSX.Element {
11551
backgroundColor,
11652
}}>
11753
<View style={styles.container}>
118-
<View style={{ marginBottom: 32 }}>
119-
<View style={{ marginBottom: 32 }}>
120-
<Text>Choose example:</Text>
121-
</View>
54+
<View style={styles.examplesContainer}>
55+
<DropDownPickerExample
56+
title="Default Example"
57+
description="This is the default dropdown picker"
58+
/>
59+
60+
<DropDownPickerExample
61+
title="Multiple Select"
62+
description="Multiple select example"
63+
multiple
64+
/>
65+
66+
<DropDownPickerExample
67+
title="Multiple Select Badge Mode"
68+
description="Multiple select example - with badges"
69+
multiple
70+
dropdownProps={{mode: "BADGE"}}
71+
/>
12272

123-
<View style={{ marginBottom: 32 }}>
124-
<DropDownPicker
125-
setValue={setCurrentExample}
126-
value={currentExample}
127-
items={exampleComponents}
128-
open={examplePickerOpen}
129-
setOpen={setOpen}
73+
<DropDownPickerExample
74+
title="Autoscroll Example"
75+
description="This is the default dropdown picker - with autoscroll"
76+
dropdownProps={{autoScroll: true}}
13077
/>
131-
</View>
132-
</View>
13378

134-
<View style={{ marginBottom: 32 }}>
135-
<View style={{ marginBottom: 32 }}>
136-
<Text>Example:</Text>
137-
</View>
13879

139-
{getExample(currentExample)}
80+
<DropDownPickerExample
81+
title="Searchable Example"
82+
description="This is the default dropdown picker - with search"
83+
dropdownProps={{searchable: true}}
84+
/>
14085
</View>
14186
</View>
14287
</View>

0 commit comments

Comments
 (0)