diff --git a/src/components/Toot/Actioned.jsx b/src/components/Toot/Actioned.jsx index 4ead4c58..e0554702 100644 --- a/src/components/Toot/Actioned.jsx +++ b/src/components/Toot/Actioned.jsx @@ -75,7 +75,8 @@ const styles = StyleSheet.create({ }) Actioned.propTypes = { - action: PropTypes.oneOf(['favourite', 'follow', 'poll', 'reblog']).isRequired, + action: PropTypes.oneOf(['favourite', 'follow', 'mention', 'poll', 'reblog']) + .isRequired, name: PropTypes.string, emojis: PropTypes.arrayOf(propTypesEmoji), notification: PropTypes.bool diff --git a/src/components/Toot/Attachment.jsx b/src/components/Toot/Attachment.jsx new file mode 100644 index 00000000..ef44da58 --- /dev/null +++ b/src/components/Toot/Attachment.jsx @@ -0,0 +1,81 @@ +import React from 'react' +import PropTypes from 'prop-types' +import propTypesAttachment from 'src/prop-types/attachment' +import { Text, View } from 'react-native' + +import AttachmentImage from './Attachment/AttachmentImage' +import AttachmentVideo from './Attachment/AttachmentVideo' + +export default function Attachment ({ media_attachments, sensitive, width }) { + let attachment + let attachmentHeight + // if (width) {} + switch (media_attachments[0].type) { + case 'unknown': + attachment = 文件不支持 + attachmentHeight = 25 + break + case 'image': + attachment = ( + + ) + attachmentHeight = width / 2 + break + case 'gifv': + attachment = ( + + ) + attachmentHeight = + (width / media_attachments[0].meta.original.width) * + media_attachments[0].meta.original.height + break + case 'video': + attachment = ( + + ) + attachmentHeight = + (width / media_attachments[0].meta.original.width) * + media_attachments[0].meta.original.height + break + // case 'audio': + // attachment = ( + // + // ) + // break + } + + return ( + + {attachment} + + ) +} + +Attachment.propTypes = { + media_attachments: PropTypes.arrayOf(propTypesAttachment), + sensitive: PropTypes.bool.isRequired, + width: PropTypes.number.isRequired +} diff --git a/src/components/Toot/Attachment/AttachmentImage.jsx b/src/components/Toot/Attachment/AttachmentImage.jsx new file mode 100644 index 00000000..1c2eda89 --- /dev/null +++ b/src/components/Toot/Attachment/AttachmentImage.jsx @@ -0,0 +1,102 @@ +import React, { useEffect, useState } from 'react' +import PropTypes from 'prop-types' +import propTypesAttachment from 'src/prop-types/attachment' +import { Button, Image, Modal, StyleSheet, Pressable, View } from 'react-native' +import ImageViewer from 'react-native-image-zoom-viewer' + +export default function AttachmentImage ({ media_attachments, sensitive, width }) { + const [mediaSensitive, setMediaSensitive] = useState(sensitive) + const [imageModalVisible, setImageModalVisible] = useState(false) + const [imageModalIndex, setImageModalIndex] = useState(0) + useEffect(() => { + if (sensitive && mediaSensitive === false) { + setTimeout(() => { + setMediaSensitive(true) + }, 10000) + } + }, [mediaSensitive]) + + let images = [] + media_attachments = media_attachments.map((m, i) => { + images.push({ + url: m.url, + width: m.meta.original.width, + height: m.meta.original.height + }) + return ( + { + setImageModalIndex(i) + setImageModalVisible(true) + }} + > + + + ) + }) + + return ( + <> + + {media_attachments} + {mediaSensitive && ( + +