2021-04-09 21:43:12 +02:00
|
|
|
import GracefullyImage from '@components/GracefullyImage'
|
2021-01-30 01:29:15 +01:00
|
|
|
import haptics from '@components/haptics'
|
|
|
|
import Icon from '@components/Icon'
|
2022-08-07 01:18:10 +02:00
|
|
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
|
2022-04-30 23:47:52 +02:00
|
|
|
import { useAppDispatch } from '@root/store'
|
2021-08-29 15:25:38 +02:00
|
|
|
import {
|
|
|
|
RootStackScreenProps,
|
|
|
|
ScreenTabsStackParamList
|
|
|
|
} from '@utils/navigation/navigators'
|
2021-02-11 23:42:13 +01:00
|
|
|
import { getPreviousTab } from '@utils/slices/contextsSlice'
|
2021-03-04 01:03:53 +01:00
|
|
|
import {
|
|
|
|
getInstanceAccount,
|
|
|
|
getInstanceActive
|
|
|
|
} from '@utils/slices/instancesSlice'
|
2022-08-07 01:18:10 +02:00
|
|
|
import { getVersionUpdate, retriveVersionLatest } from '@utils/slices/appSlice'
|
2021-01-30 01:29:15 +01:00
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2021-05-09 21:59:03 +02:00
|
|
|
import React, { useCallback, useEffect, useMemo } from 'react'
|
|
|
|
import { Platform } from 'react-native'
|
2022-04-30 23:47:52 +02:00
|
|
|
import { useSelector } from 'react-redux'
|
2021-01-30 01:29:15 +01:00
|
|
|
import TabLocal from './Tabs/Local'
|
|
|
|
import TabMe from './Tabs/Me'
|
|
|
|
import TabNotifications from './Tabs/Notifications'
|
|
|
|
import TabPublic from './Tabs/Public'
|
|
|
|
|
2021-08-29 15:25:38 +02:00
|
|
|
const Tab = createBottomTabNavigator<ScreenTabsStackParamList>()
|
2021-01-30 01:29:15 +01:00
|
|
|
|
2021-02-10 00:40:44 +01:00
|
|
|
const ScreenTabs = React.memo(
|
2021-08-29 15:25:38 +02:00
|
|
|
({ navigation }: RootStackScreenProps<'Screen-Tabs'>) => {
|
2022-08-07 01:18:10 +02:00
|
|
|
const { colors } = useTheme()
|
2021-03-02 01:17:06 +01:00
|
|
|
|
|
|
|
const instanceActive = useSelector(getInstanceActive)
|
2021-03-04 01:03:53 +01:00
|
|
|
const instanceAccount = useSelector(
|
|
|
|
getInstanceAccount,
|
|
|
|
(prev, next) => prev?.avatarStatic === next?.avatarStatic
|
2021-02-28 17:41:21 +01:00
|
|
|
)
|
|
|
|
|
2021-02-10 00:40:44 +01:00
|
|
|
const composeListeners = useMemo(
|
|
|
|
() => ({
|
|
|
|
tabPress: (e: any) => {
|
2021-01-30 01:29:15 +01:00
|
|
|
e.preventDefault()
|
2021-02-20 19:12:44 +01:00
|
|
|
haptics('Light')
|
|
|
|
navigation.navigate('Screen-Compose')
|
2021-01-30 01:29:15 +01:00
|
|
|
}
|
2021-02-10 00:40:44 +01:00
|
|
|
}),
|
2021-02-20 19:12:44 +01:00
|
|
|
[]
|
2021-02-10 00:40:44 +01:00
|
|
|
)
|
|
|
|
const composeComponent = useCallback(() => null, [])
|
|
|
|
|
2022-02-02 22:47:30 +01:00
|
|
|
const meListeners = useMemo(
|
|
|
|
() => ({
|
|
|
|
tabLongPress: () => {
|
|
|
|
haptics('Light')
|
|
|
|
//@ts-ignore
|
|
|
|
navigation.navigate('Tab-Me', { screen: 'Tab-Me-Root' })
|
|
|
|
//@ts-ignore
|
|
|
|
navigation.navigate('Tab-Me', { screen: 'Tab-Me-Switch' })
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
|
2021-02-20 19:12:44 +01:00
|
|
|
const previousTab = useSelector(getPreviousTab, () => true)
|
|
|
|
|
2021-05-09 21:59:03 +02:00
|
|
|
const versionUpdate = useSelector(getVersionUpdate)
|
2022-04-30 23:47:52 +02:00
|
|
|
const dispatch = useAppDispatch()
|
2021-05-09 21:59:03 +02:00
|
|
|
useEffect(() => {
|
|
|
|
dispatch(retriveVersionLatest())
|
|
|
|
}, [])
|
|
|
|
const tabMeOptions = useMemo(() => {
|
|
|
|
if (versionUpdate) {
|
|
|
|
return { tabBarBadge: 1 }
|
|
|
|
}
|
|
|
|
}, [versionUpdate])
|
|
|
|
|
2021-02-10 00:40:44 +01:00
|
|
|
return (
|
|
|
|
<Tab.Navigator
|
2021-02-20 19:12:44 +01:00
|
|
|
initialRouteName={instanceActive !== -1 ? previousTab : 'Tab-Me'}
|
2022-08-07 01:18:10 +02:00
|
|
|
screenOptions={({ route }) => ({
|
|
|
|
headerShown: false,
|
|
|
|
tabBarActiveTintColor: colors.primaryDefault,
|
|
|
|
tabBarInactiveTintColor: colors.secondary,
|
|
|
|
tabBarShowLabel: false,
|
|
|
|
...(Platform.OS === 'android' && { tabBarHideOnKeyboard: true }),
|
|
|
|
tabBarStyle: { display: instanceActive !== -1 ? 'flex' : 'none' },
|
|
|
|
tabBarIcon: ({
|
|
|
|
focused,
|
|
|
|
color,
|
|
|
|
size
|
|
|
|
}: {
|
|
|
|
focused: boolean
|
|
|
|
color: string
|
|
|
|
size: number
|
|
|
|
}) => {
|
|
|
|
switch (route.name) {
|
|
|
|
case 'Tab-Local':
|
|
|
|
return <Icon name='Home' size={size} color={color} />
|
|
|
|
case 'Tab-Public':
|
|
|
|
return <Icon name='Globe' size={size} color={color} />
|
|
|
|
case 'Tab-Compose':
|
|
|
|
return <Icon name='Plus' size={size} color={color} />
|
|
|
|
case 'Tab-Notifications':
|
|
|
|
return <Icon name='Bell' size={size} color={color} />
|
|
|
|
case 'Tab-Me':
|
|
|
|
return (
|
|
|
|
<GracefullyImage
|
|
|
|
key={instanceAccount?.avatarStatic}
|
|
|
|
uri={{ original: instanceAccount?.avatarStatic }}
|
|
|
|
dimension={{
|
|
|
|
width: size,
|
|
|
|
height: size
|
|
|
|
}}
|
|
|
|
style={{
|
|
|
|
borderRadius: size,
|
|
|
|
overflow: 'hidden',
|
|
|
|
borderWidth: focused ? 2 : 0,
|
|
|
|
borderColor: focused ? colors.secondary : color
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
default:
|
|
|
|
return <Icon name='AlertOctagon' size={size} color={color} />
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})}
|
2021-02-10 00:40:44 +01:00
|
|
|
>
|
2021-02-20 19:12:44 +01:00
|
|
|
<Tab.Screen name='Tab-Local' component={TabLocal} />
|
2021-02-10 00:40:44 +01:00
|
|
|
<Tab.Screen name='Tab-Public' component={TabPublic} />
|
|
|
|
<Tab.Screen
|
|
|
|
name='Tab-Compose'
|
|
|
|
component={composeComponent}
|
|
|
|
listeners={composeListeners}
|
|
|
|
/>
|
2021-03-01 00:28:14 +01:00
|
|
|
<Tab.Screen name='Tab-Notifications' component={TabNotifications} />
|
2022-02-02 22:47:30 +01:00
|
|
|
<Tab.Screen
|
|
|
|
name='Tab-Me'
|
|
|
|
component={TabMe}
|
|
|
|
options={tabMeOptions}
|
|
|
|
listeners={meListeners}
|
|
|
|
/>
|
2021-02-10 00:40:44 +01:00
|
|
|
</Tab.Navigator>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
() => true
|
|
|
|
)
|
2021-01-30 01:29:15 +01:00
|
|
|
|
|
|
|
export default ScreenTabs
|