mirror of
https://github.com/tooot-app/app
synced 2025-01-06 23:01:51 +01:00
Card use blurhash
This commit is contained in:
parent
b5b9c0669c
commit
087f50577f
@ -1,8 +1,10 @@
|
||||
import React from 'react'
|
||||
import React, { useEffect, useMemo, useState } from 'react'
|
||||
import { Image, Pressable, StyleSheet, Text, View } from 'react-native'
|
||||
import { StyleConstants } from '@utils/styles/constants'
|
||||
import { useTheme } from '@utils/styles/ThemeManager'
|
||||
import openLink from '@root/utils/openLink'
|
||||
import { Surface } from 'gl-react-expo'
|
||||
import { Blurhash } from 'gl-react-blurhash'
|
||||
|
||||
export interface Props {
|
||||
card: Mastodon.Card
|
||||
@ -11,16 +13,29 @@ export interface Props {
|
||||
const TimelineCard: React.FC<Props> = ({ card }) => {
|
||||
const { theme } = useTheme()
|
||||
|
||||
const [imageLoaded, setImageLoaded] = useState(false)
|
||||
useEffect(
|
||||
() => card.image && Image.getSize(card.image, () => setImageLoaded(true)),
|
||||
[]
|
||||
)
|
||||
const cardVisual = useMemo(() => {
|
||||
if (imageLoaded) {
|
||||
return <Image source={{ uri: card.image }} style={styles.image} />
|
||||
} else {
|
||||
return (
|
||||
<Surface style={styles.image}>
|
||||
<Blurhash hash={card.blurhash} />
|
||||
</Surface>
|
||||
)
|
||||
}
|
||||
}, [imageLoaded])
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
style={[styles.card, { borderColor: theme.border }]}
|
||||
onPress={async () => await openLink(card.url)}
|
||||
>
|
||||
{card.image && (
|
||||
<View style={styles.left}>
|
||||
<Image source={{ uri: card.image }} style={styles.image} />
|
||||
</View>
|
||||
)}
|
||||
{card.image && <View style={styles.left}>{cardVisual}</View>}
|
||||
<View style={styles.right}>
|
||||
<Text
|
||||
numberOfLines={2}
|
||||
|
Loading…
Reference in New Issue
Block a user