forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBottomNavigationExample.tsx
116 lines (107 loc) · 2.44 KB
/
BottomNavigationExample.tsx
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
115
116
import * as React from 'react';
import {
ScrollView,
View,
Image,
Dimensions,
StyleSheet,
Platform,
} from 'react-native';
import { BottomNavigation } from 'react-native-paper';
type RoutesState = Array<{
key: string;
title: string;
icon: string;
color?: string;
badge?: boolean;
getAccessibilityLabel?: string;
getTestID?: string;
}>;
type Route = { route: { key: string } };
const PhotoGallery = ({ route }: Route) => {
const PHOTOS = Array.from({ length: 24 }).map(
(_, i) => `https://unsplash.it/300/300/?random&__id=${route.key}${i}`
);
return (
<ScrollView contentContainerStyle={styles.content}>
{PHOTOS.map((uri) => (
<View key={uri} style={styles.item}>
<Image source={{ uri }} style={styles.photo} />
</View>
))}
</ScrollView>
);
};
const BottomNavigationExample = () => {
const [index, setIndex] = React.useState(0);
const [routes] = React.useState<RoutesState>([
{ key: 'album', title: 'Album', icon: 'image-album', color: '#6200ee' },
{
key: 'library',
title: 'Library',
icon: 'inbox',
color: '#2962ff',
badge: true,
},
{
key: 'favorites',
title: 'Favorites',
icon: 'heart',
color: '#00796b',
},
{
key: 'purchased',
title: 'Purchased',
icon: 'shopping-music',
color: '#c51162',
},
]);
return (
<BottomNavigation
navigationState={{ index, routes }}
onIndexChange={setIndex}
renderScene={BottomNavigation.SceneMap({
album: PhotoGallery,
library: PhotoGallery,
favorites: PhotoGallery,
purchased: PhotoGallery,
})}
/>
);
};
BottomNavigationExample.title = 'Bottom Navigation';
export default BottomNavigationExample;
const styles = StyleSheet.create({
...Platform.select({
web: {
content: {
// there is no 'grid' type in RN :(
display: 'grid' as 'none',
gridTemplateColumns: 'repeat(auto-fill, minmax(150px, 1fr))',
gridRowGap: '8px',
gridColumnGap: '8px',
padding: 8,
},
item: {
width: '100%',
height: 150,
},
},
default: {
content: {
flexDirection: 'row',
flexWrap: 'wrap',
padding: 4,
},
item: {
height: Dimensions.get('window').width / 2,
width: '50%',
padding: 4,
},
},
}),
photo: {
flex: 1,
resizeMode: 'cover',
},
});