-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBottomTabNavigator.js
47 lines (42 loc) · 1.48 KB
/
BottomTabNavigator.js
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
import * as React from 'react';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import TabBarIcon from '../components/TabBarIcon';
import HomeScreen from '../screens/HomeScreen';
import LinksScreen from '../screens/LinksScreen';
const BottomTab = createBottomTabNavigator();
const INITIAL_ROUTE_NAME = 'Home';
export default function BottomTabNavigator({ navigation, route }) {
// Set the header title on the parent stack navigator depending on the
// currently active tab. Learn more in the documentation:
// https://reactnavigation.org/docs/en/screen-options-resolution.html
navigation.setOptions({ headerTitle: getHeaderTitle(route) });
return (
<BottomTab.Navigator initialRouteName={INITIAL_ROUTE_NAME}>
<BottomTab.Screen
name="Home"
component={HomeScreen}
options={{
title: 'Get Started',
tabBarIcon: ({ focused }) => <TabBarIcon focused={focused} name="md-code-working" />,
}}
/>
<BottomTab.Screen
name="Links"
component={LinksScreen}
options={{
title: 'Resources',
tabBarIcon: ({ focused }) => <TabBarIcon focused={focused} name="md-book" />,
}}
/>
</BottomTab.Navigator>
);
}
function getHeaderTitle(route) {
const routeName = route.state?.routes[route.state.index]?.name ?? INITIAL_ROUTE_NAME;
switch (routeName) {
case 'Home':
return 'How to get started';
case 'Links':
return 'Links to learn more';
}
}