From 7712058fe4e47abd09b71dbb598275456d00d346 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 1 Nov 2022 18:53:12 +0100 Subject: [PATCH] Media Viewer: Fix video play/pause when zoomed and moving (#2094) --- src/components/mediaViewer/MediaViewerContent.tsx | 4 ++++ src/components/mediaViewer/MediaViewerSlides.tsx | 7 ++++++- src/components/mediaViewer/VideoPlayer.tsx | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/mediaViewer/MediaViewerContent.tsx b/src/components/mediaViewer/MediaViewerContent.tsx index fb9da83c5..edc6ea153 100644 --- a/src/components/mediaViewer/MediaViewerContent.tsx +++ b/src/components/mediaViewer/MediaViewerContent.tsx @@ -36,6 +36,7 @@ type OwnProps = { onFooterClick: () => void; setControlsVisible?: (isVisible: boolean) => void; areControlsVisible: boolean; + isMoving?: boolean; }; type StateProps = { @@ -73,6 +74,7 @@ const MediaViewerContent: FC = (props) => { onClose, onFooterClick, setControlsVisible, + isMoving, } = props; const isGhostAnimation = animationLevel === 2; @@ -132,6 +134,7 @@ const MediaViewerContent: FC = (props) => { isMuted shouldCloseOnClick volume={0} + isClickDisabled={isMoving} playbackRate={1} /> @@ -176,6 +179,7 @@ const MediaViewerContent: FC = (props) => { isHidden={isHidden} isProtected={isProtected} volume={volume} + isClickDisabled={isMoving} playbackRate={playbackRate} /> ))} diff --git a/src/components/mediaViewer/MediaViewerSlides.tsx b/src/components/mediaViewer/MediaViewerSlides.tsx index 590729f39..62bafc599 100644 --- a/src/components/mediaViewer/MediaViewerSlides.tsx +++ b/src/components/mediaViewer/MediaViewerSlides.tsx @@ -554,6 +554,7 @@ const MediaViewerSlides: FC = ({ setTransform(transform); }, onClick(e) { + setIsMouseDown(false); const [isInThreshold, hasNextSlide] = changeSlideOnClick(e as MouseEvent); if (isInThreshold) { e.preventDefault(); @@ -676,6 +677,7 @@ const MediaViewerSlides: FC = ({ const offsetX = transformRef.current.x; const offsetY = transformRef.current.y; const { scale } = transformRef.current; + const isMoving = isMouseDown && scale > 1; return (
@@ -685,6 +687,7 @@ const MediaViewerSlides: FC = ({ /* eslint-disable-next-line react/jsx-props-no-spreading */ {...rest} animationLevel={animationLevel} + isMoving={isMoving} areControlsVisible={areControlsVisible} mediaId={prevMediaId} /> @@ -694,7 +697,7 @@ const MediaViewerSlides: FC = ({ className={buildClassName( 'MediaViewerSlide', 'MediaViewerSlide--active', - isMouseDown && scale > 1 && 'MediaViewerSlide--moving', + isMoving && 'MediaViewerSlide--moving', )} onClick={handleControlsVisibility} ref={activeSlideRef} @@ -707,6 +710,7 @@ const MediaViewerSlides: FC = ({ animationLevel={animationLevel} isActive={isActiveRef.current} setControlsVisible={setControlsVisible} + isMoving={isMoving} areControlsVisible={areControlsVisible && scale === 1} />
@@ -716,6 +720,7 @@ const MediaViewerSlides: FC = ({ /* eslint-disable-next-line react/jsx-props-no-spreading */ {...rest} animationLevel={animationLevel} + isMoving={isMoving} areControlsVisible={areControlsVisible} mediaId={nextMediaId} /> diff --git a/src/components/mediaViewer/VideoPlayer.tsx b/src/components/mediaViewer/VideoPlayer.tsx index 8885784b5..fa916dfc2 100644 --- a/src/components/mediaViewer/VideoPlayer.tsx +++ b/src/components/mediaViewer/VideoPlayer.tsx @@ -41,6 +41,7 @@ type OwnProps = { shouldCloseOnClick?: boolean; toggleControls: (isVisible: boolean) => void; onClose: (e: React.MouseEvent) => void; + isClickDisabled?: boolean; }; const MOBILE_VERSION_CONTROL_WIDTH = 400; @@ -63,6 +64,7 @@ const VideoPlayer: FC = ({ areControlsVisible, shouldCloseOnClick, isProtected, + isClickDisabled, }) => { const { setMediaViewerVolume, @@ -156,12 +158,13 @@ const VideoPlayer: FC = ({ }, [isPlaying]); const handleClick = useCallback((e: React.MouseEvent) => { + if (isClickDisabled) return; if (shouldCloseOnClick) { onClose(e); } else { togglePlayState(e); } - }, [onClose, shouldCloseOnClick, togglePlayState]); + }, [onClose, shouldCloseOnClick, togglePlayState, isClickDisabled]); useVideoCleanup(videoRef, []);