2021-01-18 00:23:40 +01:00
|
|
|
import GracefullyImage from '@components/GracefullyImage'
|
2023-02-12 23:08:15 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
2022-12-12 22:24:03 +01:00
|
|
|
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'
|
2022-12-12 22:24:03 +01:00
|
|
|
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) => {
|
2022-12-12 22:24:03 +01:00
|
|
|
const { colors } = useTheme()
|
|
|
|
|
2022-04-30 21:29:08 +02:00
|
|
|
return (
|
2023-02-12 23:08:15 +01:00
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: colors.shimmerDefault,
|
|
|
|
alignContent: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
borderRadius: StyleConstants.BorderRadius / 2,
|
|
|
|
overflow: 'hidden'
|
|
|
|
}}
|
|
|
|
>
|
2023-02-11 23:37:17 +01:00
|
|
|
<GracefullyImage
|
|
|
|
accessibilityLabel={image.description}
|
|
|
|
hidden={sensitiveShown}
|
|
|
|
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 }) }}
|
|
|
|
dim
|
|
|
|
/>
|
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
|