From aa53533534ea3e35ca8ab90a2406afa23615831a Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Fri, 30 Oct 2020 20:03:44 +0100 Subject: [PATCH] Video working --- src/components/Toot/Actioned.jsx | 3 +- src/components/Toot/Attachment.jsx | 81 ++++++++++ .../Toot/Attachment/AttachmentImage.jsx | 102 +++++++++++++ .../Toot/Attachment/AttachmentVideo.jsx | 72 +++++++++ src/components/Toot/Media.jsx | 138 ------------------ src/components/TootNotification.jsx | 4 +- src/components/TootTimeline.jsx | 12 +- src/stacks/Notifications.jsx | 3 + src/stacks/Shared/sharedScreens.jsx | 45 ++++++ src/stacks/common/Timeline.jsx | 4 +- src/stacks/common/TimelinesCombined.jsx | 37 +---- 11 files changed, 319 insertions(+), 182 deletions(-) create mode 100644 src/components/Toot/Attachment.jsx create mode 100644 src/components/Toot/Attachment/AttachmentImage.jsx create mode 100644 src/components/Toot/Attachment/AttachmentVideo.jsx delete mode 100644 src/components/Toot/Media.jsx create mode 100644 src/stacks/Shared/sharedScreens.jsx 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 && ( + +