From bf767285286c8bee122845876beb3b71050de6da Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Tue, 28 Mar 2023 23:24:43 +0800 Subject: [PATCH] Make GIFs zoomable too --- src/components/media.jsx | 102 ++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/src/components/media.jsx b/src/components/media.jsx index 957e89de..f4682301 100644 --- a/src/components/media.jsx +++ b/src/components/media.jsx @@ -40,21 +40,39 @@ function Media({ media, showOriginal, autoAnimate, onClick = () => {} }) { focalBackgroundPosition = `${x.toFixed(0)}% ${y.toFixed(0)}%`; } - const imgRef = useRef(); + const mediaRef = useRef(); const onUpdate = useCallback(({ x, y, scale }) => { - const { current: img } = imgRef; + const { current: media } = mediaRef; - if (img) { + if (media) { const value = make3dTransformValue({ x, y, scale }); - img.style.setProperty('transform', value); + media.style.setProperty('transform', value); - img.closest('.media-zoom').style.touchAction = scale <= 1 ? 'pan-x' : ''; + media.closest('.media-zoom').style.touchAction = + scale <= 1 ? 'pan-x' : ''; } }, []); + const quickPinchZoomProps = { + draggableUnZoomed: false, + inertiaFriction: 0.9, + containerProps: { + className: 'media-zoom', + style: { + width: 'inherit', + height: 'inherit', + justifyContent: 'inherit', + alignItems: 'inherit', + // display: 'inherit', + }, + }, + onUpdate, + }; + if (type === 'image' || (type === 'unknown' && previewUrl && url)) { // Note: type: unknown might not have width/height + quickPinchZoomProps.containerProps.style.display = 'inherit'; return (
{} }) { } > {showOriginal ? ( - + {description} {} }) { const formattedDuration = formatDuration(original.duration); const hoverAnimate = !showOriginal && !autoAnimate && isGIF; const autoGIFAnimate = !showOriginal && autoAnimate && isGIF; + + const videoHTML = ` + + `; + return (
{} }) { }} > {showOriginal || autoGIFAnimate ? ( -
- `, - }} - /> + isGIF ? ( + +
+ + ) : ( +
+ ) ) : isGIF ? (