From 504f1556d597eaaa0f160fcbb33881567d46f8c5 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Mon, 12 Dec 2022 13:51:09 +0000 Subject: [PATCH] implement `FullImageViewer` --- packages/app/src/App.jsx | 15 +++++ .../app/src/components/ImageViewer/index.jsx | 58 ++++--------------- .../PostCard/components/attachments/index.jsx | 15 ++++- packages/app/src/theme/index.less | 11 ++++ 4 files changed, 49 insertions(+), 50 deletions(-) diff --git a/packages/app/src/App.jsx b/packages/app/src/App.jsx index 4dfeeb56..8e811f95 100755 --- a/packages/app/src/App.jsx +++ b/packages/app/src/App.jsx @@ -56,6 +56,7 @@ import { Toast } from "antd-mobile" import { StatusBar, Style } from "@capacitor/status-bar" import { App as CapacitorApp } from "@capacitor/app" import { Translation } from "react-i18next" +import { Lightbox } from "react-modal-image" import { Session, User } from "models" import config from "config" @@ -350,6 +351,20 @@ class App extends React.Component { }) }, openNavigationMenu: () => window.app.DrawerController.open("navigation", Navigation), + openFullImageViewer: (src) => { + const win = new DOMWindow({ + id: "fullImageViewer", + className: "fullImageViewer", + }) + + win.render( win.remove()} + hideDownload + showRotate + />) + }, goAuth: () => { return window.app.setLocation(config.app.authPath ?? "/auth") }, diff --git a/packages/app/src/components/ImageViewer/index.jsx b/packages/app/src/components/ImageViewer/index.jsx index 0c9bb35c..c5f60124 100755 --- a/packages/app/src/components/ImageViewer/index.jsx +++ b/packages/app/src/components/ImageViewer/index.jsx @@ -1,54 +1,16 @@ import React from "react" -import { Swiper } from "antd-mobile" import { LazyLoadImage } from "react-lazy-load-image-component" -import classnames from "classnames" import "react-lazy-load-image-component/src/effects/blur.css" import "./index.less" -const ImageViewer = (props) => { - React.useEffect(() => { - if (!Array.isArray(props.src)) { - props.src = [props.src] - } - }, []) - - const openViewer = () => { - if (props.extended) { - return false - } - - window.app.DrawerController.open("ImageViewer", ImageViewer, { - componentProps: { - src: props.src, - extended: true - } - }) - } - - return
- - {props.src.map((image) => { - return { - openViewer(image) - }} - > - { - openViewer() - }} - onError={(e) => { - e.target.src = "/broken-image.svg" - }} - /> - - })} - -
-} - -export default ImageViewer \ No newline at end of file +export default (props) => { + return { + e.target.src = "/broken-image.svg" + }} + /> +} \ No newline at end of file diff --git a/packages/app/src/components/PostCard/components/attachments/index.jsx b/packages/app/src/components/PostCard/components/attachments/index.jsx index d1adb65a..df56fda7 100755 --- a/packages/app/src/components/PostCard/components/attachments/index.jsx +++ b/packages/app/src/components/PostCard/components/attachments/index.jsx @@ -1,8 +1,9 @@ import React from "react" import { Skeleton } from "antd" -import loadable from "@loadable/component" import { Carousel } from "react-responsive-carousel" +import { ImageViewer } from "components" import Plyr from "plyr-react" +import ModalImage from "react-modal-image" import ContentFailed from "../contentFailed" @@ -37,6 +38,15 @@ const Attachment = React.memo((props) => { const [mediaType, setMediaType] = React.useState(null) const [mimeType, setMimeType] = React.useState(null) + const onDoubleClickAttachment = (e) => { + if (mediaType.split("/")[0] === "image") { + e.preventDefault() + e.stopPropagation() + + app.openFullImageViewer(url) + } + } + const getMediaType = async () => { let extension = null @@ -68,7 +78,7 @@ const Attachment = React.memo((props) => { const renderMedia = () => { switch (mediaType.split("/")[0]) { case "image": { - return + return } case "video": { return { key={props.index} id={id} className="attachment" + onDoubleClick={onDoubleClickAttachment} > {renderMedia()} diff --git a/packages/app/src/theme/index.less b/packages/app/src/theme/index.less index c5e01310..96252950 100755 --- a/packages/app/src/theme/index.less +++ b/packages/app/src/theme/index.less @@ -296,4 +296,15 @@ html { .postCard { min-width: 30px; } +} + +#fullImageViewer { + .__react_modal_image__modal_container { + background-color: rgba(0, 0, 0, 0.3) !important; + backdrop-filter: blur(10px); + } + + .__react_modal_image__header { + background-color: transparent !important; + } } \ No newline at end of file