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

76 lines
2.2 KiB
TypeScript
Raw Normal View History

2020-12-26 23:05:17 +01:00
import Button from '@components/Button'
2021-01-01 16:48:16 +01:00
import openLink from '@components/openLink'
import CustomText from '@components/Text'
2021-01-01 16:48:16 +01:00
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
2020-12-28 17:30:20 +01:00
import React from 'react'
2021-01-01 23:10:47 +01:00
import { useTranslation } from 'react-i18next'
import { View } from 'react-native'
2021-01-28 01:31:19 +01:00
import { Blurhash } from 'react-native-blurhash'
2022-06-03 23:18:24 +02:00
import AttachmentAltText from './AltText'
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-30 14:33:33 +01:00
sensitiveShown: boolean
2020-12-25 21:09:43 +01:00
attachment: Mastodon.AttachmentUnknown
2020-12-25 18:20:09 +01:00
}
2022-11-29 23:44:11 +01:00
const AttachmentUnsupported: React.FC<Props> = ({ total, index, sensitiveShown, attachment }) => {
2021-01-19 01:13:45 +01:00
const { t } = useTranslation('componentTimeline')
2022-02-12 14:51:01 +01:00
const { colors } = useTheme()
2021-01-01 23:10:47 +01:00
2020-12-25 18:20:09 +01:00
return (
2021-01-18 00:23:40 +01:00
<View
style={{
flex: 1,
flexBasis: '50%',
padding: StyleConstants.Spacing.XS / 2,
justifyContent: 'center',
alignItems: 'center',
aspectRatio: attachmentAspectRatio({ total, index })
}}
2021-01-18 00:23:40 +01:00
>
2020-12-28 17:30:20 +01:00
{attachment.blurhash ? (
2021-01-28 01:31:19 +01:00
<Blurhash
blurhash={attachment.blurhash}
2020-12-28 17:30:20 +01:00
style={{
position: 'absolute',
width: '100%',
height: '100%'
}}
2021-01-28 01:31:19 +01:00
/>
2020-12-28 17:30:20 +01:00
) : null}
2020-12-30 14:33:33 +01:00
{!sensitiveShown ? (
<>
<CustomText
fontStyle='S'
style={{
textAlign: 'center',
marginBottom: StyleConstants.Spacing.S,
2022-11-29 23:44:11 +01:00
color: attachment.blurhash ? colors.backgroundDefault : colors.primaryDefault
}}
2020-12-30 14:33:33 +01:00
>
2021-01-01 23:10:47 +01:00
{t('shared.attachment.unsupported.text')}
</CustomText>
2020-12-30 14:33:33 +01:00
{attachment.remote_url ? (
<Button
type='text'
2021-01-01 23:10:47 +01:00
content={t('shared.attachment.unsupported.button')}
2020-12-30 14:33:33 +01:00
size='S'
overlay
2021-04-09 21:43:12 +02:00
onPress={() => {
attachment.remote_url && openLink(attachment.remote_url)
2021-01-24 02:25:43 +01:00
}}
2020-12-30 14:33:33 +01:00
/>
) : null}
</>
2020-12-25 18:20:09 +01:00
) : null}
2022-11-29 23:44:11 +01:00
<AttachmentAltText sensitiveShown={sensitiveShown} text={attachment.description} />
2020-12-25 18:20:09 +01:00
</View>
)
}
export default AttachmentUnsupported