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

89 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import analytics from '@components/analytics'
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 { 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'
2020-12-28 17:30:20 +01:00
import { StyleSheet, Text, View } from 'react-native'
2021-01-28 01:31:19 +01:00
import { Blurhash } from 'react-native-blurhash'
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
}
2020-12-30 14:33:33 +01:00
const AttachmentUnsupported: React.FC<Props> = ({
2021-01-18 00:23:40 +01:00
total,
index,
2020-12-30 14:33:33 +01:00
sensitiveShown,
attachment
}) => {
2021-01-19 01:13:45 +01:00
const { t } = useTranslation('componentTimeline')
2020-12-25 18:20:09 +01:00
const { theme } = 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={[
styles.base,
{ aspectRatio: attachmentAspectRatio({ total, index }) }
]}
>
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 ? (
<>
<Text
style={[
styles.text,
{ color: attachment.blurhash ? theme.backgroundDefault : theme.primaryDefault }
2020-12-30 14:33:33 +01:00
]}
>
2021-01-01 23:10:47 +01:00
{t('shared.attachment.unsupported.text')}
2020-12-30 14:33:33 +01:00
</Text>
{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-01-24 02:25:43 +01:00
onPress={async () => {
analytics('timeline_shared_attachment_unsupported_press')
2021-01-22 01:34:20 +01:00
attachment.remote_url && (await 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}
</View>
)
}
const styles = StyleSheet.create({
base: {
flex: 1,
2020-12-28 17:30:20 +01:00
flexBasis: '50%',
padding: StyleConstants.Spacing.XS / 2,
2020-12-25 18:20:09 +01:00
justifyContent: 'center',
alignItems: 'center'
},
text: {
...StyleConstants.FontStyle.S,
2020-12-25 18:20:09 +01:00
textAlign: 'center',
marginBottom: StyleConstants.Spacing.S
}
})
export default AttachmentUnsupported