tooot/src/components/AccountButton.tsx

72 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-08-12 16:44:28 +02:00
import { useNavigation } from '@react-navigation/native'
2023-01-08 16:59:35 +01:00
import { ReadableAccountType, setAccount } from '@utils/storage/actions'
2022-08-12 16:44:28 +02:00
import { StyleConstants } from '@utils/styles/constants'
2023-01-29 22:18:33 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
2022-08-12 16:44:28 +02:00
import React from 'react'
2023-01-29 22:18:33 +01:00
import { Pressable } from 'react-native'
import GracefullyImage from './GracefullyImage'
2022-08-12 16:44:28 +02:00
import haptics from './haptics'
2023-01-29 22:18:33 +01:00
import Icon from './Icon'
import CustomText from './Text'
2022-08-12 16:44:28 +02:00
interface Props {
2023-01-08 16:59:35 +01:00
account: ReadableAccountType
2022-08-12 16:44:28 +02:00
additionalActions?: () => void
}
2023-01-08 16:59:35 +01:00
const AccountButton: React.FC<Props> = ({ account, additionalActions }) => {
2023-01-29 22:18:33 +01:00
const { colors } = useTheme()
2022-08-12 16:44:28 +02:00
const navigation = useNavigation()
return (
2023-01-29 22:18:33 +01:00
<Pressable
2022-08-12 16:44:28 +02:00
style={{
2023-01-29 22:18:33 +01:00
flexDirection: 'row',
alignItems: 'center',
paddingVertical: StyleConstants.Spacing.S,
paddingHorizontal: StyleConstants.Spacing.S * 1.5,
borderColor: account.active ? colors.blue : colors.border,
borderWidth: 1,
borderRadius: 99,
marginBottom: StyleConstants.Spacing.S
2022-08-12 16:44:28 +02:00
}}
2023-01-29 22:18:33 +01:00
onPress={async () => {
await setAccount(account.key)
2022-08-12 16:44:28 +02:00
haptics('Light')
navigation.goBack()
if (additionalActions) {
additionalActions()
}
}}
2023-01-29 22:18:33 +01:00
>
<GracefullyImage
2023-02-08 01:10:59 +01:00
sources={{ default: { uri: account.avatar_static } }}
2023-01-29 22:18:33 +01:00
dimension={{
width: StyleConstants.Font.Size.L,
height: StyleConstants.Font.Size.L
}}
style={{ borderRadius: StyleConstants.Font.Size.L / 2, overflow: 'hidden' }}
/>
<CustomText
fontStyle='M'
fontWeight={account.active ? 'Bold' : 'Normal'}
style={{
color: account.active ? colors.blue : colors.primaryDefault,
marginLeft: StyleConstants.Spacing.S
}}
children={account.acct}
/>
{account.active ? (
<Icon
name='check'
size={StyleConstants.Font.Size.L}
color={colors.blue}
style={{ marginLeft: StyleConstants.Spacing.S }}
/>
) : null}
</Pressable>
2022-08-12 16:44:28 +02:00
)
}
export default AccountButton