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

59 lines
1.4 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
}
const AttachmentImage: React.FC<Props> = ({
2021-01-18 00:23:40 +01:00
total,
index,
2020-12-25 18:20:09 +01:00
sensitiveShown,
image,
navigateToImagesViewer
}) => {
2021-01-24 02:25:43 +01:00
const onPress = useCallback(() => {
analytics('timeline_shared_attachment_image_press', { id: image.id })
navigateToImagesViewer(index)
}, [])
2020-12-25 18:20:09 +01:00
return (
2021-01-16 00:00:31 +01:00
<GracefullyImage
hidden={sensitiveShown}
uri={{
preview: image.preview_url,
original: image.url,
remote: image.remote_url
}}
2021-01-30 01:29:15 +01:00
sharedElement={image.url}
2021-01-16 00:00:31 +01:00
blurhash={image.blurhash}
2020-12-25 18:20:09 +01:00
onPress={onPress}
2021-01-18 00:23:40 +01:00
style={[
styles.base,
{ aspectRatio: attachmentAspectRatio({ total, index }) }
]}
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
}
})
export default React.memo(
AttachmentImage,
(prev, next) => prev.sensitiveShown === next.sensitiveShown
)