tooot/src/components/Account.tsx

87 lines
2.8 KiB
TypeScript
Raw Normal View History

2021-01-04 18:29:02 +01:00
import { ParseEmojis } from '@components/Parse'
2021-01-24 02:25:43 +01:00
import { useNavigation } from '@react-navigation/native'
import { StackNavigationProp } from '@react-navigation/stack'
2021-08-29 15:25:38 +02:00
import { TabLocalStackParamList } from '@utils/navigation/navigators'
2021-01-04 18:29:02 +01:00
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
import React, { PropsWithChildren } from 'react'
2022-12-04 12:57:03 +01:00
import { Pressable, PressableProps, View } from 'react-native'
2021-01-16 00:00:31 +01:00
import GracefullyImage from './GracefullyImage'
2022-12-04 12:57:03 +01:00
import Icon from './Icon'
import CustomText from './Text'
2021-01-04 18:29:02 +01:00
export interface Props {
2023-01-02 23:18:22 +01:00
account: Partial<Mastodon.Account> & Pick<Mastodon.Account, 'id' | 'acct' | 'username' | 'url'>
2022-12-04 12:57:03 +01:00
props?: PressableProps
2021-01-04 18:29:02 +01:00
}
2022-12-04 12:57:03 +01:00
const ComponentAccount: React.FC<PropsWithChildren & Props> = ({ account, props, children }) => {
2022-02-12 14:51:01 +01:00
const { colors } = useTheme()
2022-11-29 23:44:11 +01:00
const navigation = useNavigation<StackNavigationProp<TabLocalStackParamList>>()
2021-01-24 02:25:43 +01:00
if (!props) {
props = { onPress: () => navigation.push('Tab-Shared-Account', { account }) }
}
2021-01-04 18:29:02 +01:00
2022-12-04 12:57:03 +01:00
return (
<Pressable
{...props}
style={{
2022-11-12 17:52:50 +01:00
flex: 1,
paddingHorizontal: StyleConstants.Spacing.Global.PagePadding,
paddingVertical: StyleConstants.Spacing.M,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center'
2022-12-04 12:57:03 +01:00
}}
children={
<>
<View style={{ flex: 1, flexDirection: 'row', alignItems: 'center' }}>
<GracefullyImage
2023-02-08 01:10:59 +01:00
sources={{ default: { uri: account.avatar }, static: { uri: account.avatar_static } }}
2022-12-04 12:57:03 +01:00
style={{
width: StyleConstants.Avatar.S,
height: StyleConstants.Avatar.S,
2022-12-22 01:21:51 +01:00
borderRadius: 8,
2022-12-04 12:57:03 +01:00
marginRight: StyleConstants.Spacing.S
}}
2023-01-29 17:28:49 +01:00
dim
2022-12-04 12:57:03 +01:00
/>
2022-12-22 01:21:51 +01:00
<View style={{ flex: 1 }}>
2022-12-04 12:57:03 +01:00
<CustomText numberOfLines={1}>
<ParseEmojis
content={account.display_name || account.username}
emojis={account.emojis}
size='S'
fontBold
/>
</CustomText>
<CustomText
numberOfLines={1}
style={{
marginTop: StyleConstants.Spacing.XS,
color: colors.secondary
}}
>
@{account.acct}
</CustomText>
</View>
</View>
{props.onPress && !props.disabled ? (
<Icon
name='chevron-right'
2022-12-04 12:57:03 +01:00
size={StyleConstants.Font.Size.L}
color={colors.secondary}
style={{ marginLeft: 8 }}
/>
) : (
children || null
)}
</>
}
2022-12-04 12:57:03 +01:00
/>
2021-01-04 18:29:02 +01:00
)
}
export default ComponentAccount