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

48 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import analytics from '@components/analytics'
2021-01-18 00:23:40 +01:00
import GracefullyImage from '@components/GracefullyImage'
import { StyleConstants } from '@utils/styles/constants'
2021-01-16 00:00:31 +01:00
import React, { useCallback } from 'react'
import { StyleSheet } from 'react-native'
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
navigateToImagesViewer: (imageIndex: number) => void
}
2021-02-27 16:33:54 +01:00
const AttachmentImage = React.memo(
({ total, index, sensitiveShown, image, navigateToImagesViewer }: Props) => {
const onPress = useCallback(() => {
analytics('timeline_shared_attachment_image_press', { id: image.id })
navigateToImagesViewer(index)
}, [])
2020-12-25 18:20:09 +01:00
2021-02-27 16:33:54 +01:00
return (
<GracefullyImage
hidden={sensitiveShown}
uri={{ original: image.preview_url, remote: image.remote_url }}
blurhash={image.blurhash}
onPress={onPress}
style={[
styles.base,
{ aspectRatio: attachmentAspectRatio({ total, index }) }
]}
/>
)
},
(prev, next) => prev.sensitiveShown === next.sensitiveShown
)
2020-12-25 18:20:09 +01:00
const styles = StyleSheet.create({
2020-12-28 16:54:19 +01:00
base: {
2020-12-25 18:20:09 +01:00
flex: 1,
flexBasis: '50%',
padding: StyleConstants.Spacing.XS / 2
}
})
2021-02-27 16:33:54 +01:00
export default AttachmentImage