2021-04-09 21:43:12 +02:00
|
|
|
import GracefullyImage from '@components/GracefullyImage'
|
2021-01-30 01:29:15 +01:00
|
|
|
import Icon from '@components/Icon'
|
2023-05-15 22:30:18 +02:00
|
|
|
import haptics from '@components/haptics'
|
2022-08-07 01:18:10 +02:00
|
|
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
|
2023-01-29 16:20:31 +01:00
|
|
|
import { ScreenTabsStackParamList } from '@utils/navigation/navigators'
|
2023-05-15 22:30:18 +02:00
|
|
|
import {
|
|
|
|
getGlobalStorage,
|
|
|
|
getReadableAccounts,
|
|
|
|
setAccount,
|
|
|
|
useAccountStorage,
|
|
|
|
useGlobalStorage
|
|
|
|
} from '@utils/storage/actions'
|
2021-01-30 01:29:15 +01:00
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2023-05-15 22:30:18 +02:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
2022-12-29 00:36:35 +01:00
|
|
|
import React from 'react'
|
2023-01-29 16:20:31 +01:00
|
|
|
import { Platform, View } from 'react-native'
|
2023-05-15 22:30:18 +02:00
|
|
|
import * as ContextMenu from 'zeego/context-menu'
|
2022-12-28 23:41:36 +01:00
|
|
|
import TabLocal from './Local'
|
|
|
|
import TabMe from './Me'
|
|
|
|
import TabNotifications from './Notifications'
|
|
|
|
import TabPublic from './Public'
|
2021-01-30 01:29:15 +01:00
|
|
|
|
2021-08-29 15:25:38 +02:00
|
|
|
const Tab = createBottomTabNavigator<ScreenTabsStackParamList>()
|
2021-01-30 01:29:15 +01:00
|
|
|
|
2023-01-29 16:20:31 +01:00
|
|
|
const ScreenTabs = () => {
|
2022-12-24 01:18:20 +01:00
|
|
|
const { colors } = useTheme()
|
2021-03-02 01:17:06 +01:00
|
|
|
|
2022-12-28 23:41:36 +01:00
|
|
|
const [accountActive] = useGlobalStorage.string('account.active')
|
|
|
|
const [avatarStatic] = useAccountStorage.string('auth.account.avatar_static')
|
2021-02-28 17:41:21 +01:00
|
|
|
|
2022-12-24 01:18:20 +01:00
|
|
|
return (
|
|
|
|
<Tab.Navigator
|
2022-12-28 23:41:36 +01:00
|
|
|
initialRouteName={accountActive ? getGlobalStorage.string('app.prev_tab') : 'Tab-Me'}
|
2022-12-24 01:18:20 +01:00
|
|
|
screenOptions={({ route }) => ({
|
|
|
|
headerShown: false,
|
|
|
|
tabBarActiveTintColor: colors.primaryDefault,
|
|
|
|
tabBarInactiveTintColor: colors.secondary,
|
|
|
|
tabBarShowLabel: false,
|
|
|
|
...(Platform.OS === 'android' && { tabBarHideOnKeyboard: true }),
|
2022-12-28 23:41:36 +01:00
|
|
|
tabBarStyle: { display: accountActive ? 'flex' : 'none' },
|
2022-12-24 01:18:20 +01:00
|
|
|
tabBarIcon: ({
|
|
|
|
focused,
|
|
|
|
color,
|
|
|
|
size
|
|
|
|
}: {
|
|
|
|
focused: boolean
|
|
|
|
color: string
|
|
|
|
size: number
|
|
|
|
}) => {
|
|
|
|
switch (route.name) {
|
|
|
|
case 'Tab-Local':
|
2023-01-25 00:15:46 +01:00
|
|
|
return <Icon name='home' size={size} color={color} />
|
2022-12-24 01:18:20 +01:00
|
|
|
case 'Tab-Public':
|
2023-01-25 00:15:46 +01:00
|
|
|
return <Icon name='globe' size={size} color={color} />
|
2022-12-24 01:18:20 +01:00
|
|
|
case 'Tab-Compose':
|
2023-01-25 00:15:46 +01:00
|
|
|
return <Icon name='plus' size={size} color={color} />
|
2022-12-24 01:18:20 +01:00
|
|
|
case 'Tab-Notifications':
|
2023-01-25 00:15:46 +01:00
|
|
|
return <Icon name='bell' size={size} color={color} />
|
2022-12-24 01:18:20 +01:00
|
|
|
case 'Tab-Me':
|
|
|
|
return (
|
2023-05-15 22:30:18 +02:00
|
|
|
<>
|
2023-05-17 13:39:55 +02:00
|
|
|
<ContextMenu.Root>
|
2023-05-15 22:30:18 +02:00
|
|
|
<ContextMenu.Trigger>
|
|
|
|
<View
|
|
|
|
key={avatarStatic}
|
|
|
|
style={{ flexDirection: 'row', alignItems: 'center' }}
|
|
|
|
>
|
|
|
|
<GracefullyImage
|
|
|
|
sources={{ default: { uri: avatarStatic } }}
|
|
|
|
dimension={{ width: size, height: size }}
|
|
|
|
style={{
|
|
|
|
borderRadius: 99,
|
|
|
|
overflow: 'hidden',
|
|
|
|
borderWidth: focused ? 2 : 0,
|
|
|
|
borderColor: focused ? colors.primaryDefault : color
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Icon name='more-vertical' size={size / 1.5} color={colors.secondary} />
|
|
|
|
</View>
|
|
|
|
</ContextMenu.Trigger>
|
|
|
|
|
|
|
|
<ContextMenu.Content>
|
|
|
|
<ContextMenu.Preview preferredCommitStyle='pop'>
|
|
|
|
{() => (
|
|
|
|
<View
|
|
|
|
key={avatarStatic}
|
|
|
|
style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
padding: StyleConstants.Spacing.M
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<GracefullyImage
|
|
|
|
sources={{ default: { uri: avatarStatic } }}
|
|
|
|
dimension={{ width: size, height: size }}
|
|
|
|
style={{
|
|
|
|
borderRadius: 99,
|
|
|
|
overflow: 'hidden',
|
|
|
|
borderWidth: 2,
|
|
|
|
borderColor: colors.primaryDefault
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
</ContextMenu.Preview>
|
|
|
|
|
|
|
|
{getReadableAccounts().map(account => (
|
|
|
|
<ContextMenu.CheckboxItem
|
|
|
|
key={account.key}
|
|
|
|
value={account.active ? 'on' : 'off'}
|
|
|
|
disabled={account.active}
|
|
|
|
onValueChange={async () => {
|
|
|
|
if (!account.active) {
|
|
|
|
await setAccount(account.key)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<ContextMenu.ItemTitle children={account.acct} />
|
|
|
|
</ContextMenu.CheckboxItem>
|
|
|
|
))}
|
|
|
|
</ContextMenu.Content>
|
|
|
|
</ContextMenu.Root>
|
|
|
|
</>
|
2022-12-24 01:18:20 +01:00
|
|
|
)
|
|
|
|
default:
|
2023-01-25 00:15:46 +01:00
|
|
|
return <Icon name='alert-octagon' size={size} color={color} />
|
2022-08-07 01:18:10 +02:00
|
|
|
}
|
2022-12-24 01:18:20 +01:00
|
|
|
}
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<Tab.Screen name='Tab-Local' component={TabLocal} />
|
|
|
|
<Tab.Screen name='Tab-Public' component={TabPublic} />
|
2022-12-29 00:36:35 +01:00
|
|
|
<Tab.Screen
|
|
|
|
name='Tab-Compose'
|
2023-01-29 16:20:31 +01:00
|
|
|
listeners={({ navigation }) => ({
|
2022-12-29 00:36:35 +01:00
|
|
|
tabPress: e => {
|
|
|
|
e.preventDefault()
|
|
|
|
haptics('Light')
|
|
|
|
navigation.navigate('Screen-Compose')
|
|
|
|
}
|
2023-01-29 16:20:31 +01:00
|
|
|
})}
|
2022-12-29 00:36:35 +01:00
|
|
|
>
|
|
|
|
{() => null}
|
|
|
|
</Tab.Screen>
|
2022-12-24 01:18:20 +01:00
|
|
|
<Tab.Screen name='Tab-Notifications' component={TabNotifications} />
|
2023-05-17 13:39:55 +02:00
|
|
|
<Tab.Screen name='Tab-Me' component={TabMe} />
|
2022-12-24 01:18:20 +01:00
|
|
|
</Tab.Navigator>
|
|
|
|
)
|
|
|
|
}
|
2021-01-30 01:29:15 +01:00
|
|
|
|
|
|
|
export default ScreenTabs
|