-
Notifications
You must be signed in to change notification settings - Fork 2
/
NavigationController.js
104 lines (93 loc) · 3.7 KB
/
NavigationController.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
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 React, { useContext } from 'react'
import { connect } from 'react-redux'
import { Image } from 'react-native'
import { NavigationContainer } from '@react-navigation/native'
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import Ionicons from 'react-native-vector-icons/Ionicons'
import * as Haptics from 'expo-haptics'
import { HomeStack, DiscoveryStack, SettingsStack } from './src/stacks'
import { CrosswordsScreen } from './src/screens'
import { PublicationPrimaryColor } from './src/utils/branding'
import { PublicationEnum } from './src/utils/constants'
import { navigationRef, ThemeContext } from './src/components'
const DP_LOGO_RED = require('./src/static/logos/dp-logo-small-red.png')
const DP_LOGO_GREY = require('./src/static/logos/dp-logo-small-grey.png')
const STREET_LOGO_TEAL = require('./src/static/logos/street-logo-small-teal.png')
const STREET_LOGO_GREY = require('./src/static/logos/street-logo-small-grey.png')
const UTB_LOGO_BLUE = require('./src/static/logos/utb-logo-small-blue.png')
const UTB_LOGO_GREY = require('./src/static/logos/utb-logo-small-grey.png')
const Tab = createBottomTabNavigator()
const TabNavigationController = ({ currPublication }) => {
const theme = useContext(ThemeContext)
const routeNameRef = React.useRef()
const GET_PUB_LOGO = focused => {
switch (currPublication) {
case PublicationEnum.dp:
return focused ? DP_LOGO_RED : DP_LOGO_GREY
case PublicationEnum.street:
return focused ? STREET_LOGO_TEAL : STREET_LOGO_GREY
default:
return focused ? UTB_LOGO_BLUE : UTB_LOGO_GREY
}
}
return (
<NavigationContainer
ref={navigationRef}
// linking={linking}
onReady={() =>
(routeNameRef.current = navigationRef.current.getCurrentRoute().name)
}
onStateChange={() => {
routeNameRef.current = navigationRef.current.getCurrentRoute().name
}}
>
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ color, focused }) => {
let iconName
if (route.name === 'HomeStack') {
return (
<Image
source={GET_PUB_LOGO(focused)}
style={{
height: 26,
width: 45,
resizeMode: 'contain',
alignSelf: 'center',
}}
/>
)
} else if (route.name === 'DiscoveryStack') iconName = 'search'
else if (route.name === 'SettingsStack') iconName = 'person-outline'
else if (route.name === 'CrosswordsScreen') iconName = 'grid-outline'
return <Ionicons name={iconName} size={26} color={color} />
},
})}
tabBarOptions={{
activeTintColor: PublicationPrimaryColor(currPublication),
inactiveTintColor: 'gray',
showLabel: false,
style: {
backgroundColor: theme.backgroundColor,
shadowColor: theme.primaryTextColor,
shadowOpacity: 0.1,
shadowRadius: 4,
},
onPress: () => {
// Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)
},
}}
>
<Tab.Screen name="HomeStack" component={HomeStack} />
<Tab.Screen name="DiscoveryStack" component={DiscoveryStack} />
<Tab.Screen name="CrosswordsScreen" component={CrosswordsScreen} />
<Tab.Screen name="SettingsStack" component={SettingsStack} />
</Tab.Navigator>
</NavigationContainer>
)
}
const mapStateToProps = ({ publication }) => {
const { currPublication } = publication
return { currPublication }
}
export default connect(mapStateToProps)(TabNavigationController)