-
-
Notifications
You must be signed in to change notification settings - Fork 5k
/
BottomTabs.tsx
173 lines (160 loc) · 4.71 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { useActionSheet } from '@expo/react-native-action-sheet';
import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons';
import {
createBottomTabNavigator,
TransitionPresets,
useBottomTabBarHeight,
} from '@react-navigation/bottom-tabs';
import { HeaderBackButton, useHeaderHeight } from '@react-navigation/elements';
import {
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 { Appbar } from 'react-native-paper';
import { Albums } from '../Shared/Albums';
import { Chat } from '../Shared/Chat';
import { Contacts } from '../Shared/Contacts';
import { SimpleStack, 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 Tab = createBottomTabNavigator<BottomTabParams>();
const animations = {
shifting: TransitionPresets.ShiftingTransition,
fade: TransitionPresets.FadeTransition,
none: null,
} as const;
export function BottomTabs({
navigation,
}: StackScreenProps<ParamListBase, string>) {
React.useLayoutEffect(() => {
navigation.setOptions({
headerShown: false,
});
}, [navigation]);
const [animation, setAnimation] =
React.useState<keyof typeof animations>('none');
const { showActionSheetWithOptions } = useActionSheet();
return (
<Tab.Navigator
screenOptions={{
headerLeft: (props) => (
<HeaderBackButton {...props} onPress={navigation.goBack} />
),
headerRight: ({ tintColor }) => (
<Appbar.Action
icon={animation === 'none' ? 'heart-outline' : 'heart'}
color={tintColor}
onPress={() => {
const options = Object.keys(
animations
) as (keyof typeof animations)[];
showActionSheetWithOptions(
{
options: options.map((option) => {
if (option === animation) {
return `${option} (current)`;
}
return option;
}),
},
(index) => {
if (index != null) {
setAnimation(options[index]);
}
}
);
}}
/>
),
...animations[animation],
}}
>
<Tab.Screen
name="TabStack"
component={SimpleStack}
options={{
title: 'Article',
tabBarIcon: getTabBarIcon('file-document'),
}}
/>
<Tab.Screen
name="TabChat"
component={Chat}
options={{
tabBarLabel: 'Chat',
tabBarIcon: getTabBarIcon('message-reply'),
tabBarBadge: 2,
}}
/>
<Tab.Screen
name="TabContacts"
component={Contacts}
options={{
title: 'Contacts',
tabBarIcon: getTabBarIcon('contacts'),
}}
/>
<Tab.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}
/>
),
}}
/>
</Tab.Navigator>
);
}