tooot/src/components/Timeline/Shared/Avatar.tsx

57 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-02-14 00:27:21 +01:00
import analytics from '@components/analytics'
2021-01-16 00:00:31 +01:00
import GracefullyImage from '@components/GracefullyImage'
2021-02-14 00:27:21 +01:00
import { useNavigation } from '@react-navigation/native'
2021-01-24 02:25:43 +01:00
import { StackNavigationProp } from '@react-navigation/stack'
2022-04-29 23:57:18 +02:00
import { TabLocalStackParamList } from '@utils/navigation/navigators'
2021-02-14 00:27:21 +01:00
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
import { StyleConstants } from '@utils/styles/constants'
import React, { useCallback } from 'react'
2021-04-09 21:43:12 +02:00
import { useTranslation } from 'react-i18next'
2020-11-23 00:07:32 +01:00
2020-10-31 21:04:46 +01:00
export interface Props {
2021-01-07 19:13:09 +01:00
queryKey?: QueryKeyTimeline
2020-12-03 01:28:56 +01:00
account: Mastodon.Account
2021-04-09 21:43:12 +02:00
highlighted: boolean
2020-10-31 21:04:46 +01:00
}
2021-02-27 16:33:54 +01:00
const TimelineAvatar = React.memo(
2021-04-09 21:43:12 +02:00
({ queryKey, account, highlighted }: Props) => {
const { t } = useTranslation('componentTimeline')
2022-02-12 18:25:53 +01:00
const navigation =
2022-04-29 23:57:18 +02:00
useNavigation<StackNavigationProp<TabLocalStackParamList>>()
2021-02-27 16:33:54 +01:00
// Need to fix go back root
const onPress = useCallback(() => {
analytics('timeline_shared_avatar_press', {
page: queryKey && queryKey[1].page
})
queryKey && navigation.push('Tab-Shared-Account', { account })
}, [])
2020-11-28 17:07:30 +01:00
2021-02-27 16:33:54 +01:00
return (
<GracefullyImage
2021-04-09 21:43:12 +02:00
{...(highlighted && {
accessibilityLabel: t('shared.avatar.accessibilityLabel', {
name: account.display_name
}),
accessibilityHint: t('shared.avatar.accessibilityHint', {
name: account.display_name
})
})}
2021-02-27 16:33:54 +01:00
onPress={onPress}
2022-02-19 17:09:34 +01:00
uri={{ original: account?.avatar, static: account?.avatar_static }}
2021-02-27 16:33:54 +01:00
dimension={{
width: StyleConstants.Avatar.M,
height: StyleConstants.Avatar.M
}}
style={{
2021-03-27 00:02:32 +01:00
borderRadius: StyleConstants.Avatar.M,
2021-02-27 16:33:54 +01:00
overflow: 'hidden',
2021-04-09 21:43:12 +02:00
marginRight: StyleConstants.Spacing.S
2021-02-27 16:33:54 +01:00
}}
/>
)
2022-04-30 21:47:17 +02:00
}
2021-02-27 16:33:54 +01:00
)
2020-10-25 01:35:41 +02:00
2021-02-27 16:33:54 +01:00
export default TimelineAvatar