From d01f44ac24600839083a0b0313741b42c3a090e2 Mon Sep 17 00:00:00 2001
From: xueweihan <595666367@qq.com>
Date: Mon, 17 Jun 2024 00:45:29 +0800
Subject: [PATCH] feat: gif button
---
src/components/ImageWithPreview.tsx | 57 +++++++++++++++++++++---
src/components/loading/GifPlayButton.tsx | 40 +++++++++++++++++
2 files changed, 90 insertions(+), 7 deletions(-)
create mode 100644 src/components/loading/GifPlayButton.tsx
diff --git a/src/components/ImageWithPreview.tsx b/src/components/ImageWithPreview.tsx
index da677302..76490e9a 100644
--- a/src/components/ImageWithPreview.tsx
+++ b/src/components/ImageWithPreview.tsx
@@ -1,17 +1,60 @@
import RcImage, { ImageProps } from 'rc-image';
+import { useEffect, useState } from 'react';
import { AiOutlineClose } from 'react-icons/ai';
import 'rc-image/assets/index.css';
+import GifPlayButton from './loading/GifPlayButton';
+
const ImageWithPreview = (props: ImageProps) => {
+ const [imgSrc, setImgSrc] = useState(
+ props.src?.endsWith('gif') ? `${props.src}!gif` : (props.src as string)
+ );
+ const isGifThumb = imgSrc.endsWith('!gif');
+ const isGif = imgSrc?.endsWith('gif') && !isGifThumb;
+ const sourceIsGif = props.src?.endsWith('gif');
+
+ useEffect(() => {
+ if (props.src?.endsWith('gif')) {
+ setImgSrc(`${props.src}!gif`);
+ } else {
+ setImgSrc(props.src as string);
+ }
+ }, [props.src]);
+
+ const handleLoadGif = (e: any) => {
+ e.stopPropagation();
+ setTimeout(() => {
+ if (sourceIsGif) {
+ setImgSrc(imgSrc?.replace('!gif', ''));
+ }
+ }, 300);
+ };
+
return (
-