-
-
Notifications
You must be signed in to change notification settings - Fork 5k
/
BottomTabs.tsx
135 lines (126 loc) · 3.66 KB
/
BottomTabs.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
124
125
126
127
128
129
130
131
132
133
134
135
import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons';
import {
createBottomTabNavigator,
useBottomTabBarHeight,
} from '@react-navigation/bottom-tabs';
import { HeaderBackButton, useHeaderHeight } from '@react-navigation/elements';
import {
getFocusedRouteNameFromRoute,
NavigatorScreenParams,
ParamListBase,
useIsFocused,
} from '@react-navigation/native';
import type { StackScreenProps } from '@react-navigation/stack';
import { BlurView } from 'expo-blur';
import * as React from 'react';
import { ScrollView, StatusBar, StyleSheet } from 'react-native';
import Albums from '../Shared/Albums';
import Chat from '../Shared/Chat';
import Contacts from '../Shared/Contacts';
import SimpleStackScreen, { SimpleStackParams } from './SimpleStack';
const getTabBarIcon =
(name: React.ComponentProps<typeof MaterialCommunityIcons>['name']) =>
({ color, size }: { color: string; size: number }) =>
<MaterialCommunityIcons name={name} color={color} size={size} />;
type BottomTabParams = {
TabStack: NavigatorScreenParams<SimpleStackParams>;
TabAlbums: undefined;
TabContacts: undefined;
TabChat: undefined;
};
const AlbumsScreen = () => {
const headerHeight = useHeaderHeight();
const tabBarHeight = useBottomTabBarHeight();
const isFocused = useIsFocused();
return (
<>
{isFocused && <StatusBar barStyle="light-content" />}
<ScrollView
contentContainerStyle={{
paddingTop: headerHeight,
paddingBottom: tabBarHeight,
}}
>
<Albums scrollEnabled={false} />
</ScrollView>
</>
);
};
const BottomTabs = createBottomTabNavigator<BottomTabParams>();
export default function BottomTabsScreen({
navigation,
route,
}: StackScreenProps<ParamListBase, string>) {
const routeName = getFocusedRouteNameFromRoute(route) ?? 'Article';
React.useLayoutEffect(() => {
navigation.setOptions({
headerShown: false,
title: routeName,
});
}, [navigation, routeName]);
return (
<BottomTabs.Navigator
screenOptions={{
headerLeft: (props) => (
<HeaderBackButton {...props} onPress={navigation.goBack} />
),
}}
>
<BottomTabs.Screen
name="TabStack"
component={SimpleStackScreen}
options={{
title: 'Article',
tabBarIcon: getTabBarIcon('file-document'),
}}
/>
<BottomTabs.Screen
name="TabChat"
component={Chat}
options={{
tabBarLabel: 'Chat',
tabBarIcon: getTabBarIcon('message-reply'),
tabBarBadge: 2,
}}
/>
<BottomTabs.Screen
name="TabContacts"
component={Contacts}
options={{
title: 'Contacts',
tabBarIcon: getTabBarIcon('contacts'),
}}
/>
<BottomTabs.Screen
name="TabAlbums"
component={AlbumsScreen}
options={{
title: 'Albums',
headerTintColor: '#fff',
headerTransparent: true,
headerBackground: () => (
<BlurView
tint="dark"
intensity={100}
style={StyleSheet.absoluteFill}
/>
),
tabBarIcon: getTabBarIcon('image-album'),
tabBarInactiveTintColor: 'rgba(255, 255, 255, 0.5)',
tabBarActiveTintColor: '#fff',
tabBarStyle: {
position: 'absolute',
borderTopColor: 'rgba(0, 0, 0, .2)',
},
tabBarBackground: () => (
<BlurView
tint="dark"
intensity={100}
style={StyleSheet.absoluteFill}
/>
),
}}
/>
</BottomTabs.Navigator>
);
}