2020-12-03 01:28:56 +01:00
|
|
|
import { BlurView } from 'expo-blur'
|
|
|
|
import React, { useCallback, useEffect, useState } from 'react'
|
|
|
|
import { Pressable, StyleSheet, Text, View } from 'react-native'
|
2020-12-13 14:04:25 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2020-10-30 20:03:44 +01:00
|
|
|
|
2020-12-13 14:04:25 +01:00
|
|
|
import AttachmentImage from '@components/Timelines/Timeline/Shared/Attachment/AttachmentImage'
|
|
|
|
import AttachmentVideo from '@components/Timelines/Timeline/Shared/Attachment/AttachmentVideo'
|
2020-10-30 20:03:44 +01:00
|
|
|
|
2020-10-31 21:04:46 +01:00
|
|
|
export interface Props {
|
2020-12-03 01:28:56 +01:00
|
|
|
status: Pick<Mastodon.Status, 'media_attachments' | 'sensitive'>
|
2020-10-31 21:04:46 +01:00
|
|
|
width: number
|
|
|
|
}
|
|
|
|
|
2020-12-03 01:28:56 +01:00
|
|
|
const TimelineAttachment: React.FC<Props> = ({ status, width }) => {
|
|
|
|
const { mode, theme } = useTheme()
|
|
|
|
const allTypes = status.media_attachments.map(m => m.type)
|
2020-10-30 20:03:44 +01:00
|
|
|
let attachment
|
|
|
|
let attachmentHeight
|
2020-12-03 01:28:56 +01:00
|
|
|
|
|
|
|
if (allTypes.includes('image')) {
|
|
|
|
attachment = (
|
|
|
|
<AttachmentImage
|
|
|
|
media_attachments={status.media_attachments}
|
|
|
|
width={width}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
attachmentHeight = (width / 16) * 9
|
|
|
|
} else if (allTypes.includes('gifv')) {
|
|
|
|
attachment = (
|
|
|
|
<AttachmentVideo
|
|
|
|
media_attachments={status.media_attachments}
|
|
|
|
width={width}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
attachmentHeight =
|
|
|
|
status.media_attachments[0].meta?.original?.width &&
|
|
|
|
status.media_attachments[0].meta?.original?.height
|
|
|
|
? (width / status.media_attachments[0].meta.original.width) *
|
|
|
|
status.media_attachments[0].meta.original.height
|
|
|
|
: (width / 16) * 9
|
|
|
|
} else if (allTypes.includes('video')) {
|
|
|
|
attachment = (
|
|
|
|
<AttachmentVideo
|
|
|
|
media_attachments={status.media_attachments}
|
|
|
|
width={width}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
attachmentHeight =
|
|
|
|
status.media_attachments[0].meta?.original?.width &&
|
|
|
|
status.media_attachments[0].meta?.original?.height
|
|
|
|
? (width / status.media_attachments[0].meta.original.width) *
|
|
|
|
status.media_attachments[0].meta.original.height
|
|
|
|
: (width / 16) * 9
|
|
|
|
} else if (allTypes.includes('audio')) {
|
2020-10-30 20:03:44 +01:00
|
|
|
// attachment = (
|
|
|
|
// <AttachmentAudio
|
|
|
|
// media_attachments={media_attachments}
|
|
|
|
// sensitive={sensitive}
|
|
|
|
// width={width}
|
|
|
|
// />
|
|
|
|
// )
|
2020-12-03 01:28:56 +01:00
|
|
|
} else {
|
|
|
|
attachment = <Text>文件不支持</Text>
|
|
|
|
attachmentHeight = 25
|
2020-10-30 20:03:44 +01:00
|
|
|
}
|
|
|
|
|
2020-12-03 01:28:56 +01:00
|
|
|
const [sensitiveShown, setSensitiveShown] = useState(true)
|
|
|
|
const onPressBlurView = useCallback(() => {
|
|
|
|
setSensitiveShown(false)
|
|
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
|
|
if (status.sensitive && sensitiveShown === false) {
|
|
|
|
setTimeout(() => {
|
|
|
|
setSensitiveShown(true)
|
|
|
|
}, 10000)
|
|
|
|
}
|
|
|
|
}, [sensitiveShown])
|
|
|
|
|
2020-10-30 20:03:44 +01:00
|
|
|
return (
|
|
|
|
<View
|
|
|
|
style={{
|
2020-12-03 01:28:56 +01:00
|
|
|
width: width + StyleConstants.Spacing.XS,
|
2020-10-30 20:03:44 +01:00
|
|
|
height: attachmentHeight,
|
2020-12-03 01:28:56 +01:00
|
|
|
marginTop: StyleConstants.Spacing.S,
|
|
|
|
marginLeft: -StyleConstants.Spacing.XS / 2
|
2020-10-30 20:03:44 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{attachment}
|
2020-12-03 01:28:56 +01:00
|
|
|
{status.sensitive && sensitiveShown && (
|
|
|
|
<BlurView tint={mode} intensity={100} style={styles.blurView}>
|
|
|
|
<Pressable onPress={onPressBlurView} style={styles.blurViewPressable}>
|
|
|
|
<Text style={[styles.sensitiveText, { color: theme.primary }]}>
|
|
|
|
显示敏感内容
|
|
|
|
</Text>
|
|
|
|
</Pressable>
|
|
|
|
</BlurView>
|
|
|
|
)}
|
2020-10-30 20:03:44 +01:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-03 01:28:56 +01:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
blurView: {
|
|
|
|
position: 'absolute',
|
|
|
|
width: '100%',
|
|
|
|
height: '100%'
|
|
|
|
},
|
|
|
|
blurViewPressable: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
sensitiveText: {
|
|
|
|
fontSize: StyleConstants.Font.Size.M
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default React.memo(TimelineAttachment, () => true)
|