tooot/src/screens/Tabs/index.tsx

152 lines
5.6 KiB
TypeScript
Raw Normal View History

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'
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'
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 = () => {
const { colors } = useTheme()
2021-03-02 01:17:06 +01:00
const [accountActive] = useGlobalStorage.string('account.active')
const [avatarStatic] = useAccountStorage.string('auth.account.avatar_static')
2021-02-28 17:41:21 +01:00
return (
<Tab.Navigator
initialRouteName={accountActive ? getGlobalStorage.string('app.prev_tab') : 'Tab-Me'}
screenOptions={({ route }) => ({
headerShown: false,
tabBarActiveTintColor: colors.primaryDefault,
tabBarInactiveTintColor: colors.secondary,
tabBarShowLabel: false,
...(Platform.OS === 'android' && { tabBarHideOnKeyboard: true }),
tabBarStyle: { display: accountActive ? '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 (
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>
</>
)
default:
return <Icon name='alert-octagon' size={size} color={color} />
2022-08-07 01:18:10 +02:00
}
}
})}
>
<Tab.Screen name='Tab-Local' component={TabLocal} />
<Tab.Screen name='Tab-Public' component={TabPublic} />
<Tab.Screen
name='Tab-Compose'
2023-01-29 16:20:31 +01:00
listeners={({ navigation }) => ({
tabPress: e => {
e.preventDefault()
haptics('Light')
navigation.navigate('Screen-Compose')
}
2023-01-29 16:20:31 +01:00
})}
>
{() => null}
</Tab.Screen>
<Tab.Screen name='Tab-Notifications' component={TabNotifications} />
2023-05-17 13:39:55 +02:00
<Tab.Screen name='Tab-Me' component={TabMe} />
</Tab.Navigator>
)
}
2021-01-30 01:29:15 +01:00
export default ScreenTabs