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

100 lines
2.5 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
}
2021-02-27 16:33:54 +01:00
const TimelineCard = React.memo(
({ card }: Props) => {
const { theme } = useTheme()
2020-11-28 17:07:30 +01:00
2021-02-27 16:33:54 +01:00
return (
<Pressable
style={[styles.card, { borderColor: theme.border }]}
onPress={async () => {
analytics('timeline_shared_card_press')
await openLink(card.url)
}}
testID='base'
>
{card.image && (
<GracefullyImage
uri={{ original: card.image }}
blurhash={card.blurhash}
style={styles.left}
imageStyle={styles.image}
/>
)}
<View style={styles.right}>
<Text
numberOfLines={2}
style={[styles.rightTitle, { color: theme.primaryDefault }]}
2021-02-27 16:33:54 +01:00
testID='title'
>
{card.title}
</Text>
{card.description ? (
<Text
numberOfLines={1}
style={[styles.rightDescription, { color: theme.primaryDefault }]}
2021-02-27 16:33:54 +01:00
testID='description'
>
{card.description}
</Text>
) : null}
2020-12-01 00:44:28 +01:00
<Text
numberOfLines={1}
2021-02-27 16:33:54 +01:00
style={[styles.rightLink, { color: theme.secondary }]}
2020-12-01 00:44:28 +01:00
>
2021-02-27 16:33:54 +01:00
{card.url}
2020-12-01 00:44:28 +01:00
</Text>
2021-02-27 16:33:54 +01:00
</View>
</Pressable>
)
},
() => true
)
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
}
})
2021-02-27 16:33:54 +01:00
export default TimelineCard