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

97 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'
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, Text, View } from 'react-native'
2020-10-29 14:52:28 +01:00
2020-10-31 21:04:46 +01:00
export interface Props {
card: Mastodon.Card
2020-10-31 21:04:46 +01:00
}
2020-12-03 01:28:56 +01:00
const TimelineCard: React.FC<Props> = ({ card }) => {
2020-12-01 00:44:28 +01:00
const { theme } = useTheme()
2020-11-28 17:07:30 +01:00
2020-10-29 14:52:28 +01:00
return (
2020-12-01 00:44:28 +01:00
<Pressable
style={[styles.card, { borderColor: theme.border }]}
2021-01-24 02:25:43 +01:00
onPress={async () => {
analytics('timeline_shared_card_press')
await openLink(card.url)
}}
2021-01-10 02:12:14 +01:00
testID='base'
2020-12-01 00:44:28 +01:00
>
2021-01-10 02:12:14 +01:00
{card.image && (
2021-01-16 00:00:31 +01:00
<GracefullyImage
uri={{ original: card.image }}
blurhash={card.blurhash}
style={styles.left}
2021-02-02 22:50:38 +01:00
imageStyle={styles.image}
2021-01-16 00:00:31 +01:00
/>
2021-01-10 02:12:14 +01:00
)}
2020-11-28 17:07:30 +01:00
<View style={styles.right}>
2020-12-01 00:44:28 +01:00
<Text
numberOfLines={2}
style={[styles.rightTitle, { color: theme.primary }]}
2021-01-10 02:12:14 +01:00
testID='title'
2020-12-01 00:44:28 +01:00
>
{card.title}
</Text>
2020-11-28 17:07:30 +01:00
{card.description ? (
2020-12-01 00:44:28 +01:00
<Text
numberOfLines={1}
style={[styles.rightDescription, { color: theme.primary }]}
2021-01-10 02:12:14 +01:00
testID='description'
2020-12-01 00:44:28 +01:00
>
{card.description}
</Text>
2020-12-13 23:38:37 +01:00
) : null}
2021-01-24 02:25:43 +01:00
<Text
numberOfLines={1}
style={[styles.rightLink, { color: theme.secondary }]}
>
2020-12-01 00:44:28 +01:00
{card.url}
</Text>
2020-11-28 17:07:30 +01:00
</View>
</Pressable>
2020-10-29 14:52:28 +01:00
)
}
const styles = StyleSheet.create({
card: {
flex: 1,
flexDirection: 'row',
2021-01-24 02:25:43 +01:00
height: StyleConstants.Font.LineHeight.M * 5,
2020-12-01 00:44:28 +01:00
marginTop: StyleConstants.Spacing.M,
2020-12-03 22:03:06 +01:00
borderWidth: StyleSheet.hairlineWidth,
2021-02-02 22:50:38 +01:00
borderRadius: 6,
overflow: 'hidden'
2020-10-29 14:52:28 +01:00
},
left: {
2021-02-02 22:50:38 +01:00
flexBasis: StyleConstants.Font.LineHeight.M * 5
2020-10-29 14:52:28 +01:00
},
image: {
2020-12-01 00:44:28 +01:00
borderTopLeftRadius: 6,
borderBottomLeftRadius: 6
2020-10-29 14:52:28 +01:00
},
right: {
2020-12-01 00:44:28 +01:00
flex: 1,
padding: StyleConstants.Spacing.S
},
rightTitle: {
2021-01-24 02:25:43 +01:00
...StyleConstants.FontStyle.S,
2020-12-01 00:44:28 +01:00
marginBottom: StyleConstants.Spacing.XS,
fontWeight: StyleConstants.Font.Weight.Bold
},
rightDescription: {
2021-01-24 02:25:43 +01:00
...StyleConstants.FontStyle.S,
2020-12-01 00:44:28 +01:00
marginBottom: StyleConstants.Spacing.XS
2021-01-24 02:25:43 +01:00
},
rightLink: {
...StyleConstants.FontStyle.S
2020-10-29 14:52:28 +01:00
}
})
2020-12-03 01:28:56 +01:00
export default React.memo(TimelineCard, () => true)