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

89 lines
2.4 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import analytics from '@components/analytics'
2021-01-16 00:00:31 +01:00
import GracefullyImage from '@components/GracefullyImage'
2021-01-01 16:48:16 +01:00
import openLink from '@components/openLink'
import CustomText from '@components/Text'
2021-03-21 23:06:53 +01:00
import { useNavigation } from '@react-navigation/native'
2020-12-13 14:04:25 +01:00
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
2021-01-16 00:00:31 +01:00
import React from 'react'
import { Pressable, StyleSheet, View } from 'react-native'
2020-10-29 14:52:28 +01:00
2020-10-31 21:04:46 +01:00
export interface Props {
2022-04-30 21:47:17 +02:00
card: Pick<
Mastodon.Card,
'url' | 'image' | 'blurhash' | 'title' | 'description'
>
2020-10-31 21:04:46 +01:00
}
2022-04-30 21:47:17 +02:00
const TimelineCard = React.memo(({ card }: Props) => {
const { colors } = useTheme()
const navigation = useNavigation()
2020-11-28 17:07:30 +01:00
2022-04-30 21:47:17 +02:00
return (
<Pressable
accessible
accessibilityRole='link'
style={{
flex: 1,
flexDirection: 'row',
height: StyleConstants.Font.LineHeight.M * 5,
marginTop: StyleConstants.Spacing.M,
borderWidth: StyleSheet.hairlineWidth,
borderRadius: 6,
overflow: 'hidden',
borderColor: colors.border
}}
2022-04-30 21:47:17 +02:00
onPress={async () => {
analytics('timeline_shared_card_press')
await openLink(card.url, navigation)
}}
testID='base'
>
{card.image ? (
<GracefullyImage
uri={{ original: card.image }}
blurhash={card.blurhash}
style={{ flexBasis: StyleConstants.Font.LineHeight.M * 5 }}
imageStyle={{ borderTopLeftRadius: 6, borderBottomLeftRadius: 6 }}
2022-04-30 21:47:17 +02:00
/>
) : null}
<View style={{ flex: 1, padding: StyleConstants.Spacing.S }}>
<CustomText
fontStyle='S'
2022-04-30 21:47:17 +02:00
numberOfLines={2}
style={{
marginBottom: StyleConstants.Spacing.XS,
color: colors.primaryDefault
}}
2022-05-10 23:19:26 +02:00
fontWeight='Bold'
2022-04-30 21:47:17 +02:00
testID='title'
>
{card.title}
</CustomText>
2022-04-30 21:47:17 +02:00
{card.description ? (
<CustomText
fontStyle='S'
2020-12-01 00:44:28 +01:00
numberOfLines={1}
style={{
marginBottom: StyleConstants.Spacing.XS,
color: colors.primaryDefault
}}
2022-04-30 21:47:17 +02:00
testID='description'
2020-12-01 00:44:28 +01:00
>
2022-04-30 21:47:17 +02:00
{card.description}
</CustomText>
2022-04-30 21:47:17 +02:00
) : null}
<CustomText
fontStyle='S'
2022-04-30 21:47:17 +02:00
numberOfLines={1}
style={{ color: colors.secondary }}
2022-04-30 21:47:17 +02:00
>
{card.url}
</CustomText>
2022-04-30 21:47:17 +02:00
</View>
</Pressable>
)
})
2020-10-29 14:52:28 +01:00
2021-02-27 16:33:54 +01:00
export default TimelineCard