tooot/src/components/Timeline/Shared/Attachment/Image.tsx

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-01-18 00:23:40 +01:00
import GracefullyImage from '@components/GracefullyImage'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
2022-04-30 21:29:08 +02:00
import React from 'react'
import { View } from 'react-native'
2022-06-03 23:18:24 +02:00
import AttachmentAltText from './AltText'
import { aspectRatio } from './dimensions'
2020-12-25 18:20:09 +01:00
export interface Props {
2021-01-18 00:23:40 +01:00
total: number
index: number
2020-12-25 18:20:09 +01:00
sensitiveShown: boolean
image: Mastodon.AttachmentImage
2021-03-06 23:42:29 +01:00
navigateToImagesViewer: (imageIndex: string) => void
2020-12-25 18:20:09 +01:00
}
2022-04-30 21:29:08 +02:00
const AttachmentImage = ({
total,
index,
sensitiveShown,
image,
navigateToImagesViewer
}: Props) => {
const { colors } = useTheme()
2022-04-30 21:29:08 +02:00
return (
<View
style={{
flex: 1,
flexBasis: '50%',
padding: StyleConstants.Spacing.XS / 2
}}
>
<View style={{ flex: 1, backgroundColor: colors.shimmerDefault }}>
<GracefullyImage
accessibilityLabel={image.description}
hidden={sensitiveShown}
2023-02-08 01:10:59 +01:00
sources={{
default: { uri: image.preview_url },
remote: { uri: image.remote_url },
blurhash: image.blurhash
}}
onPress={() => navigateToImagesViewer(image.id)}
style={{ aspectRatio: aspectRatio({ total, index, ...image.meta?.original }) }}
2023-01-29 17:28:49 +01:00
dim
/>
</View>
2022-11-29 23:44:11 +01:00
<AttachmentAltText sensitiveShown={sensitiveShown} text={image.description} />
2022-04-30 21:29:08 +02:00
</View>
)
}
2020-12-25 18:20:09 +01:00
2021-02-27 16:33:54 +01:00
export default AttachmentImage