forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSegmentedButtonRealCase.tsx
More file actions
97 lines (89 loc) · 2.26 KB
/
SegmentedButtonRealCase.tsx
File metadata and controls
97 lines (89 loc) · 2.26 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
import * as React from 'react';
import { FlatList, StyleSheet, View } from 'react-native';
import { Card, IconButton, SegmentedButtons } from 'react-native-paper';
import { songsData, albumsData } from '../../../utils';
type MediaType = 'songs' | 'albums';
const SegmentedButtonRealCase = () => {
const [value, setValue] = React.useState<MediaType>('songs');
return (
<View style={styles.container}>
<SegmentedButtons<MediaType>
value={value}
onValueChange={setValue}
buttons={[
{
value: 'songs',
label: 'Songs',
style: styles.button,
showSelectedCheck: true,
},
{
value: 'albums',
label: 'Albums',
style: styles.button,
showSelectedCheck: true,
},
]}
style={styles.group}
/>
<FlatList
data={value === 'songs' ? songsData : albumsData}
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.title}
subtitle={item.artist}
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',
paddingBottom: 8,
},
});
SegmentedButtonRealCase.title = 'Music player';
export default SegmentedButtonRealCase;