Media Viewer: Fix video play/pause when zoomed and moving (#2094)
This commit is contained in:
parent
df19a8489b
commit
7712058fe4
@ -36,6 +36,7 @@ type OwnProps = {
|
|||||||
onFooterClick: () => void;
|
onFooterClick: () => void;
|
||||||
setControlsVisible?: (isVisible: boolean) => void;
|
setControlsVisible?: (isVisible: boolean) => void;
|
||||||
areControlsVisible: boolean;
|
areControlsVisible: boolean;
|
||||||
|
isMoving?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type StateProps = {
|
type StateProps = {
|
||||||
@ -73,6 +74,7 @@ const MediaViewerContent: FC<OwnProps & StateProps> = (props) => {
|
|||||||
onClose,
|
onClose,
|
||||||
onFooterClick,
|
onFooterClick,
|
||||||
setControlsVisible,
|
setControlsVisible,
|
||||||
|
isMoving,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const isGhostAnimation = animationLevel === 2;
|
const isGhostAnimation = animationLevel === 2;
|
||||||
@ -132,6 +134,7 @@ const MediaViewerContent: FC<OwnProps & StateProps> = (props) => {
|
|||||||
isMuted
|
isMuted
|
||||||
shouldCloseOnClick
|
shouldCloseOnClick
|
||||||
volume={0}
|
volume={0}
|
||||||
|
isClickDisabled={isMoving}
|
||||||
playbackRate={1}
|
playbackRate={1}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -176,6 +179,7 @@ const MediaViewerContent: FC<OwnProps & StateProps> = (props) => {
|
|||||||
isHidden={isHidden}
|
isHidden={isHidden}
|
||||||
isProtected={isProtected}
|
isProtected={isProtected}
|
||||||
volume={volume}
|
volume={volume}
|
||||||
|
isClickDisabled={isMoving}
|
||||||
playbackRate={playbackRate}
|
playbackRate={playbackRate}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -554,6 +554,7 @@ const MediaViewerSlides: FC<OwnProps> = ({
|
|||||||
setTransform(transform);
|
setTransform(transform);
|
||||||
},
|
},
|
||||||
onClick(e) {
|
onClick(e) {
|
||||||
|
setIsMouseDown(false);
|
||||||
const [isInThreshold, hasNextSlide] = changeSlideOnClick(e as MouseEvent);
|
const [isInThreshold, hasNextSlide] = changeSlideOnClick(e as MouseEvent);
|
||||||
if (isInThreshold) {
|
if (isInThreshold) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -676,6 +677,7 @@ const MediaViewerSlides: FC<OwnProps> = ({
|
|||||||
const offsetX = transformRef.current.x;
|
const offsetX = transformRef.current.x;
|
||||||
const offsetY = transformRef.current.y;
|
const offsetY = transformRef.current.y;
|
||||||
const { scale } = transformRef.current;
|
const { scale } = transformRef.current;
|
||||||
|
const isMoving = isMouseDown && scale > 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="MediaViewerSlides" ref={containerRef}>
|
<div className="MediaViewerSlides" ref={containerRef}>
|
||||||
@ -685,6 +687,7 @@ const MediaViewerSlides: FC<OwnProps> = ({
|
|||||||
/* eslint-disable-next-line react/jsx-props-no-spreading */
|
/* eslint-disable-next-line react/jsx-props-no-spreading */
|
||||||
{...rest}
|
{...rest}
|
||||||
animationLevel={animationLevel}
|
animationLevel={animationLevel}
|
||||||
|
isMoving={isMoving}
|
||||||
areControlsVisible={areControlsVisible}
|
areControlsVisible={areControlsVisible}
|
||||||
mediaId={prevMediaId}
|
mediaId={prevMediaId}
|
||||||
/>
|
/>
|
||||||
@ -694,7 +697,7 @@ const MediaViewerSlides: FC<OwnProps> = ({
|
|||||||
className={buildClassName(
|
className={buildClassName(
|
||||||
'MediaViewerSlide',
|
'MediaViewerSlide',
|
||||||
'MediaViewerSlide--active',
|
'MediaViewerSlide--active',
|
||||||
isMouseDown && scale > 1 && 'MediaViewerSlide--moving',
|
isMoving && 'MediaViewerSlide--moving',
|
||||||
)}
|
)}
|
||||||
onClick={handleControlsVisibility}
|
onClick={handleControlsVisibility}
|
||||||
ref={activeSlideRef}
|
ref={activeSlideRef}
|
||||||
@ -707,6 +710,7 @@ const MediaViewerSlides: FC<OwnProps> = ({
|
|||||||
animationLevel={animationLevel}
|
animationLevel={animationLevel}
|
||||||
isActive={isActiveRef.current}
|
isActive={isActiveRef.current}
|
||||||
setControlsVisible={setControlsVisible}
|
setControlsVisible={setControlsVisible}
|
||||||
|
isMoving={isMoving}
|
||||||
areControlsVisible={areControlsVisible && scale === 1}
|
areControlsVisible={areControlsVisible && scale === 1}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -716,6 +720,7 @@ const MediaViewerSlides: FC<OwnProps> = ({
|
|||||||
/* eslint-disable-next-line react/jsx-props-no-spreading */
|
/* eslint-disable-next-line react/jsx-props-no-spreading */
|
||||||
{...rest}
|
{...rest}
|
||||||
animationLevel={animationLevel}
|
animationLevel={animationLevel}
|
||||||
|
isMoving={isMoving}
|
||||||
areControlsVisible={areControlsVisible}
|
areControlsVisible={areControlsVisible}
|
||||||
mediaId={nextMediaId}
|
mediaId={nextMediaId}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -41,6 +41,7 @@ type OwnProps = {
|
|||||||
shouldCloseOnClick?: boolean;
|
shouldCloseOnClick?: boolean;
|
||||||
toggleControls: (isVisible: boolean) => void;
|
toggleControls: (isVisible: boolean) => void;
|
||||||
onClose: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
onClose: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
||||||
|
isClickDisabled?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const MOBILE_VERSION_CONTROL_WIDTH = 400;
|
const MOBILE_VERSION_CONTROL_WIDTH = 400;
|
||||||
@ -63,6 +64,7 @@ const VideoPlayer: FC<OwnProps> = ({
|
|||||||
areControlsVisible,
|
areControlsVisible,
|
||||||
shouldCloseOnClick,
|
shouldCloseOnClick,
|
||||||
isProtected,
|
isProtected,
|
||||||
|
isClickDisabled,
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
setMediaViewerVolume,
|
setMediaViewerVolume,
|
||||||
@ -156,12 +158,13 @@ const VideoPlayer: FC<OwnProps> = ({
|
|||||||
}, [isPlaying]);
|
}, [isPlaying]);
|
||||||
|
|
||||||
const handleClick = useCallback((e: React.MouseEvent<HTMLVideoElement, MouseEvent>) => {
|
const handleClick = useCallback((e: React.MouseEvent<HTMLVideoElement, MouseEvent>) => {
|
||||||
|
if (isClickDisabled) return;
|
||||||
if (shouldCloseOnClick) {
|
if (shouldCloseOnClick) {
|
||||||
onClose(e);
|
onClose(e);
|
||||||
} else {
|
} else {
|
||||||
togglePlayState(e);
|
togglePlayState(e);
|
||||||
}
|
}
|
||||||
}, [onClose, shouldCloseOnClick, togglePlayState]);
|
}, [onClose, shouldCloseOnClick, togglePlayState, isClickDisabled]);
|
||||||
|
|
||||||
useVideoCleanup(videoRef, []);
|
useVideoCleanup(videoRef, []);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user