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

49 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-01-16 00:00:31 +01:00
import React, { useCallback } from 'react'
import { StyleSheet } from 'react-native'
2020-12-25 18:20:09 +01:00
import { StyleConstants } from '@utils/styles/constants'
2021-01-16 00:00:31 +01:00
import GracefullyImage from '@components/GracefullyImage'
2020-12-25 18:20:09 +01:00
export interface Props {
sensitiveShown: boolean
image: Mastodon.AttachmentImage
imageIndex: number
navigateToImagesViewer: (imageIndex: number) => void
}
const AttachmentImage: React.FC<Props> = ({
sensitiveShown,
image,
imageIndex,
navigateToImagesViewer
}) => {
2020-12-28 16:54:19 +01:00
const onPress = useCallback(() => navigateToImagesViewer(imageIndex), [])
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
}}
blurhash={image.blurhash}
2020-12-25 18:20:09 +01:00
onPress={onPress}
2021-01-16 00:00:31 +01:00
style={styles.base}
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%',
2020-12-28 16:54:19 +01:00
aspectRatio: 16 / 9,
2020-12-25 18:20:09 +01:00
padding: StyleConstants.Spacing.XS / 2
}
})
export default React.memo(
AttachmentImage,
(prev, next) => prev.sensitiveShown === next.sensitiveShown
)