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

87 lines
2.1 KiB
TypeScript
Raw Normal View History

2020-11-28 17:07:30 +01:00
import React, { useCallback } from 'react'
2020-10-29 14:52:28 +01:00
import { Image, Pressable, StyleSheet, Text, View } from 'react-native'
import { useNavigation } from '@react-navigation/native'
2020-12-01 00:44:28 +01:00
import { StyleConstants } from 'src/utils/styles/constants'
import { useTheme } from 'src/utils/styles/ThemeManager'
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-10-29 14:52:28 +01:00
const navigation = useNavigation()
2020-11-28 17:07:30 +01:00
const onPress = useCallback(() => {
navigation.navigate('Screen-Shared-Webview', {
uri: card.url
})
}, [])
2020-10-29 14:52:28 +01:00
return (
2020-12-01 00:44:28 +01:00
<Pressable
style={[styles.card, { borderColor: theme.border }]}
onPress={onPress}
>
2020-11-28 17:07:30 +01:00
{card.image && (
<View style={styles.left}>
<Image source={{ uri: card.image }} style={styles.image} />
2020-10-29 14:52:28 +01:00
</View>
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 }]}
>
{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 }]}
>
{card.description}
</Text>
2020-11-28 17:07:30 +01:00
) : (
<></>
)}
2020-12-01 00:44:28 +01:00
<Text numberOfLines={1} style={{ color: theme.secondary }}>
{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',
2020-12-01 00:44:28 +01:00
height: StyleConstants.Avatar.L,
marginTop: StyleConstants.Spacing.M,
2020-12-03 22:03:06 +01:00
borderWidth: StyleSheet.hairlineWidth,
2020-12-01 00:44:28 +01:00
borderRadius: 6
2020-10-29 14:52:28 +01:00
},
left: {
2020-12-01 00:44:28 +01:00
width: StyleConstants.Avatar.L
2020-10-29 14:52:28 +01:00
},
image: {
width: '100%',
2020-12-01 00:44:28 +01:00
height: '100%',
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: {
marginBottom: StyleConstants.Spacing.XS,
fontWeight: StyleConstants.Font.Weight.Bold
},
rightDescription: {
marginBottom: StyleConstants.Spacing.XS
2020-10-29 14:52:28 +01:00
}
})
2020-12-03 01:28:56 +01:00
export default React.memo(TimelineCard, () => true)