1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Clean up react memo

This commit is contained in:
Zhiyuan Zheng
2022-04-30 21:47:17 +02:00
parent f93d6f7db8
commit 293447f65c
8 changed files with 93 additions and 82 deletions

View File

@ -8,65 +8,62 @@ import React from 'react'
import { Pressable, StyleSheet, Text, View } from 'react-native'
export interface Props {
card: Mastodon.Card
card: Pick<
Mastodon.Card,
'url' | 'image' | 'blurhash' | 'title' | 'description'
>
}
const TimelineCard = React.memo(
({ card }: Props) => {
const { colors } = useTheme()
const navigation = useNavigation()
const TimelineCard = React.memo(({ card }: Props) => {
const { colors } = useTheme()
const navigation = useNavigation()
return (
<Pressable
accessible
accessibilityRole='link'
style={[styles.card, { borderColor: colors.border }]}
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={styles.left}
imageStyle={styles.image}
/>
) : null}
<View style={styles.right}>
<Text
numberOfLines={2}
style={[styles.rightTitle, { color: colors.primaryDefault }]}
testID='title'
>
{card.title}
</Text>
{card.description ? (
<Text
numberOfLines={1}
style={[
styles.rightDescription,
{ color: colors.primaryDefault }
]}
testID='description'
>
{card.description}
</Text>
) : null}
return (
<Pressable
accessible
accessibilityRole='link'
style={[styles.card, { borderColor: colors.border }]}
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={styles.left}
imageStyle={styles.image}
/>
) : null}
<View style={styles.right}>
<Text
numberOfLines={2}
style={[styles.rightTitle, { color: colors.primaryDefault }]}
testID='title'
>
{card.title}
</Text>
{card.description ? (
<Text
numberOfLines={1}
style={[styles.rightLink, { color: colors.secondary }]}
style={[styles.rightDescription, { color: colors.primaryDefault }]}
testID='description'
>
{card.url}
{card.description}
</Text>
</View>
</Pressable>
)
},
() => true
)
) : null}
<Text
numberOfLines={1}
style={[styles.rightLink, { color: colors.secondary }]}
>
{card.url}
</Text>
</View>
</Pressable>
)
})
const styles = StyleSheet.create({
card: {