/
BottomNavigationExample.tsx
123 lines (116 loc) · 2.5 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
117
118
119
120
121
122
123
import * as React from 'react';
import {
ScrollView,
View,
Image,
Dimensions,
StyleSheet,
Platform,
} from 'react-native';
import { BottomNavigation } from 'react-native-paper';
type State = {
index: number;
routes: Array<{
key: string;
title: string;
icon: string;
color?: string;
badge?: boolean;
getAccessibilityLabel?: string;
getTestID?: string;
}>;
};
const PhotoGallery = ({ route }: any) => {
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>
);
};
export default class BottomNavigationExample extends React.Component<
{},
State
> {
static title = 'Bottom Navigation';
state = {
index: 0,
routes: [
{ key: 'album', title: 'Album', icon: 'image-album', color: '#272727' },
{
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',
},
],
};
render() {
return (
<BottomNavigation
navigationState={this.state}
onIndexChange={index => this.setState({ index })}
// @ts-ignore
renderScene={BottomNavigation.SceneMap({
album: PhotoGallery,
library: PhotoGallery,
favorites: PhotoGallery,
purchased: PhotoGallery,
})}
/>
);
}
}
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',
},
});