-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathSegmentedButtonMultiselectRealCase.tsx
More file actions
114 lines (105 loc) · 2.72 KB
/
SegmentedButtonMultiselectRealCase.tsx
File metadata and controls
114 lines (105 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import * as React from 'react';
import { FlatList, StyleSheet, View } from 'react-native';
import { Card, IconButton, SegmentedButtons } from 'react-native-paper';
import { restaurantsData } from '../../../utils';
type PriceRange = '1' | '2' | '3' | '4';
const SegmentedButtonMultiselectRealCase = () => {
const [value, setValue] = React.useState<PriceRange[]>([]);
const filteredData = React.useMemo(
() =>
restaurantsData.filter((item) =>
value.includes(item.price.toString() as PriceRange)
),
[value]
);
return (
<View style={styles.container}>
<SegmentedButtons
value={value}
onValueChange={setValue}
multiSelect
buttons={[
{
value: '1',
label: '$',
style: styles.button,
showSelectedCheck: true,
},
{
value: '2',
label: '$$',
style: styles.button,
showSelectedCheck: true,
},
{
value: '3',
label: '$$$',
style: styles.button,
showSelectedCheck: true,
},
{
value: '4',
label: '$$$$',
style: styles.button,
showSelectedCheck: true,
},
]}
style={styles.group}
/>
<FlatList
data={value.length > 0 ? filteredData : restaurantsData}
keyExtractor={(item) => item.id}
contentContainerStyle={styles.contentContainer}
renderItem={({ item }) => {
return (
<Card mode="contained" style={styles.card}>
<Card.Content style={styles.content}>
<Card.Cover style={styles.cover} source={item.cover} />
<Card.Title
title={item.name}
subtitle={'$'.repeat(item.price)}
titleVariant="titleMedium"
style={styles.title}
right={() => <IconButton icon={'bookmark-outline'} />}
/>
</Card.Content>
</Card>
);
}}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
marginVertical: 16,
flex: 1,
},
contentContainer: {
paddingBottom: 16,
},
card: {
marginHorizontal: 16,
marginTop: 16,
},
content: {
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 0,
paddingVertical: 0,
},
cover: {
width: 72,
height: 72,
},
title: {
flexShrink: 1,
marginVertical: 0,
},
button: {
flex: 1,
},
group: { paddingHorizontal: 20, justifyContent: 'center' },
});
SegmentedButtonMultiselectRealCase.title = 'Restaurants';
export default SegmentedButtonMultiselectRealCase;