2020-10-30 20:03:44 +01:00
|
|
|
import React from 'react'
|
|
|
|
import { Text, View } from 'react-native'
|
|
|
|
|
|
|
|
import AttachmentImage from './Attachment/AttachmentImage'
|
|
|
|
import AttachmentVideo from './Attachment/AttachmentVideo'
|
|
|
|
|
2020-10-31 21:04:46 +01:00
|
|
|
export interface Props {
|
2020-11-21 00:40:55 +01:00
|
|
|
media_attachments: Mastodon.Attachment[]
|
2020-10-31 21:04:46 +01:00
|
|
|
sensitive: boolean
|
|
|
|
width: number
|
|
|
|
}
|
|
|
|
|
|
|
|
const Attachment: React.FC<Props> = ({
|
|
|
|
media_attachments,
|
|
|
|
sensitive,
|
|
|
|
width
|
|
|
|
}) => {
|
2020-10-30 20:03:44 +01:00
|
|
|
let attachment
|
|
|
|
let attachmentHeight
|
|
|
|
// if (width) {}
|
|
|
|
switch (media_attachments[0].type) {
|
|
|
|
case 'unknown':
|
|
|
|
attachment = <Text>文件不支持</Text>
|
|
|
|
attachmentHeight = 25
|
|
|
|
break
|
|
|
|
case 'image':
|
|
|
|
attachment = (
|
|
|
|
<AttachmentImage
|
|
|
|
media_attachments={media_attachments}
|
|
|
|
sensitive={sensitive}
|
|
|
|
width={width}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
attachmentHeight = width / 2
|
|
|
|
break
|
|
|
|
case 'gifv':
|
|
|
|
attachment = (
|
|
|
|
<AttachmentVideo
|
|
|
|
media_attachments={media_attachments}
|
|
|
|
sensitive={sensitive}
|
|
|
|
width={width}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
attachmentHeight =
|
|
|
|
(width / media_attachments[0].meta.original.width) *
|
|
|
|
media_attachments[0].meta.original.height
|
|
|
|
break
|
2020-11-09 01:04:47 +01:00
|
|
|
// Support multiple video
|
|
|
|
// Supoort when video meta is empty
|
|
|
|
// case 'video':
|
|
|
|
// attachment = (
|
|
|
|
// <AttachmentVideo
|
|
|
|
// media_attachments={media_attachments}
|
|
|
|
// sensitive={sensitive}
|
|
|
|
// width={width}
|
|
|
|
// />
|
|
|
|
// )
|
|
|
|
// attachmentHeight =
|
|
|
|
// (width / media_attachments[0].meta.original.width) *
|
|
|
|
// media_attachments[0].meta.original.height
|
|
|
|
// break
|
2020-10-30 20:03:44 +01:00
|
|
|
// case 'audio':
|
|
|
|
// attachment = (
|
|
|
|
// <AttachmentAudio
|
|
|
|
// media_attachments={media_attachments}
|
|
|
|
// sensitive={sensitive}
|
|
|
|
// width={width}
|
|
|
|
// />
|
|
|
|
// )
|
|
|
|
// break
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
width: width + 8,
|
|
|
|
height: attachmentHeight,
|
|
|
|
marginTop: 4,
|
|
|
|
marginLeft: -4
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{attachment}
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-10-31 21:04:46 +01:00
|
|
|
export default Attachment
|