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

52 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'
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'
2021-01-18 00:23:40 +01:00
import attachmentAspectRatio from './aspectRatio'
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) => {
return (
<View
style={{
flex: 1,
flexBasis: '50%',
padding: StyleConstants.Spacing.XS / 2
}}
>
<GracefullyImage
accessibilityLabel={image.description}
hidden={sensitiveShown}
uri={{ original: image.preview_url, remote: image.remote_url }}
blurhash={image.blurhash}
2022-11-29 23:44:11 +01:00
onPress={() => navigateToImagesViewer(image.id)}
2022-04-30 21:29:08 +02:00
style={{
aspectRatio:
2022-11-29 23:44:11 +01:00
total > 1 || !image.meta?.original?.width || !image.meta?.original?.height
2022-04-30 21:29:08 +02:00
? attachmentAspectRatio({ total, index })
: image.meta.original.height / image.meta.original.width > 1
? 1
: image.meta.original.width / image.meta.original.height
}}
/>
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