forked from callstack/react-native-bottom-tabs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomTabBar.tsx
More file actions
104 lines (99 loc) · 2.35 KB
/
Copy pathCustomTabBar.tsx
File metadata and controls
104 lines (99 loc) · 2.35 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
import TabView from 'react-native-bottom-tabs';
import { useState } from 'react';
import { Pressable, StyleSheet, Text, View } from 'react-native';
const routes = [
{
key: 'article',
title: 'Article',
focusedIcon: require('../../assets/icons/article_dark.png'),
},
{
key: 'albums',
title: 'Albums',
focusedIcon: require('../../assets/icons/grid_dark.png'),
},
{
key: 'contacts',
title: 'Contacts',
focusedIcon: require('../../assets/icons/person_dark.png'),
},
];
export default function CustomTabBar() {
const [index, setIndex] = useState(0);
return (
<TabView
sidebarAdaptable
navigationState={{ index, routes }}
onIndexChange={setIndex}
renderScene={({ route }) => (
<View style={styles.screen}>
<Text style={styles.title}>{route.title}</Text>
</View>
)}
tabBar={() => (
<View style={styles.customTabBar}>
{routes.map((route, routeIndex) => {
const focused = routeIndex === index;
return (
<Pressable
key={route.key}
style={[
styles.customTabBarItem,
focused && styles.customTabBarItemFocused,
]}
onPress={() => setIndex(routeIndex)}
>
<Text
style={[
styles.customTabBarLabel,
focused && styles.customTabBarLabelFocused,
]}
>
{route.title}
</Text>
</Pressable>
);
})}
</View>
)}
/>
);
}
const styles = StyleSheet.create({
screen: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 24,
},
title: {
fontSize: 24,
fontWeight: '600',
},
customTabBar: {
flexDirection: 'row',
gap: 8,
paddingHorizontal: 12,
paddingTop: 10,
paddingBottom: 18,
backgroundColor: '#24292f',
},
customTabBarItem: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
minHeight: 44,
borderRadius: 6,
backgroundColor: '#3b434c',
},
customTabBarItemFocused: {
backgroundColor: '#ffffff',
},
customTabBarLabel: {
color: '#ffffff',
fontWeight: '600',
},
customTabBarLabelFocused: {
color: '#24292f',
},
});