import Button from '@components/Button' import haptics from '@components/haptics' import AttachmentAudio from '@components/Timelines/Timeline/Shared/Attachment/Audio' import AttachmentImage from '@components/Timelines/Timeline/Shared/Attachment/Image' import AttachmentUnsupported from '@components/Timelines/Timeline/Shared/Attachment/Unsupported' import AttachmentVideo from '@components/Timelines/Timeline/Shared/Attachment/Video' import { useNavigation } from '@react-navigation/native' import { StyleConstants } from '@utils/styles/constants' import layoutAnimation from '@utils/styles/layoutAnimation' import React, { useCallback, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { Pressable, StyleSheet, View } from 'react-native' import { IImageInfo } from 'react-native-image-zoom-viewer/built/image-viewer.type' export interface Props { status: Pick } const TimelineAttachment: React.FC = ({ status }) => { const { t } = useTranslation('timeline') const [sensitiveShown, setSensitiveShown] = useState(status.sensitive) const onPressBlurView = useCallback(() => { layoutAnimation() setSensitiveShown(false) haptics('Medium') }, []) const onPressShow = useCallback(() => { setSensitiveShown(true) haptics('Medium') }, []) let imageUrls: (IImageInfo & { preview_url: Mastodon.AttachmentImage['preview_url'] remote_url?: Mastodon.AttachmentImage['remote_url'] imageIndex: number })[] = [] const navigation = useNavigation() const navigateToImagesViewer = (imageIndex: number) => navigation.navigate('Screen-Shared-ImagesViewer', { imageUrls, imageIndex }) const attachments = useMemo( () => status.media_attachments.map((attachment, index) => { switch (attachment.type) { case 'image': imageUrls.push({ url: attachment.url, width: attachment.meta?.original?.width, height: attachment.meta?.original?.height, preview_url: attachment.preview_url, remote_url: attachment.remote_url, imageIndex: index }) return ( ) case 'video': return ( ) case 'gifv': return ( ) case 'audio': return ( ) default: return ( ) } }), [sensitiveShown] ) return ( {attachments} {status.sensitive && (sensitiveShown ? (