From 37fb14816db32489afdc4afa8b94f62296f14d15 Mon Sep 17 00:00:00 2001 From: danidfra Date: Thu, 31 Oct 2024 17:55:09 -0300 Subject: [PATCH 1/2] Update video feature --- src/features/video/index.tsx | 64 +++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/src/features/video/index.tsx b/src/features/video/index.tsx index 438e84378..c9f1fa966 100644 --- a/src/features/video/index.tsx +++ b/src/features/video/index.tsx @@ -6,6 +6,7 @@ import { defineMessages, useIntl } from 'react-intl'; import Blurhash from 'soapbox/components/blurhash'; import SvgIcon from 'soapbox/components/ui/icon/svg-icon'; +import { useIsMobile } from 'soapbox/hooks/useIsMobile'; import { isPanoramic, isPortrait, minimumAspectRatio, maximumAspectRatio } from 'soapbox/utils/media-aspect-ratio'; import { isFullscreen, requestFullscreen, exitFullscreen } from '../ui/util/fullscreen'; @@ -129,11 +130,13 @@ const Video: React.FC = ({ blurhash, }) => { const intl = useIntl(); + const isMobile = useIsMobile(); const player = useRef(null); const video = useRef(null); const seek = useRef(null); const slider = useRef(null); + const timeoutRef = useRef(null); const [currentTime, setCurrentTime] = useState(0); const [duration, setDuration] = useState(0); @@ -144,6 +147,7 @@ const Video: React.FC = ({ const [containerWidth, setContainerWidth] = useState(width); const [fullscreen, setFullscreen] = useState(false); const [hovered, setHovered] = useState(false); + const [volumeHovered, setVolumeHovered] = useState(false); const [seekHovered, setSeekHovered] = useState(false); const [muted, setMuted] = useState(false); const [buffer, setBuffer] = useState(0); @@ -397,6 +401,36 @@ const Video: React.FC = ({ setSeekHovered(false); }; + const handleVolumeEnter = () => { + setVolumeHovered(true); + }; + + const handleVolumeLeave = () => { + setVolumeHovered(false); + }; + + const handleClickStart = () => { + setHovered(true); + setHovered(true); + + if (timeoutRef.current) { + clearTimeout(timeoutRef.current); + timeoutRef.current = null; + } + + timeoutRef.current = setTimeout(() => { + setHovered(false); + }, 2 * 1000); + + }; + + const handleOnMouseMove = () => { + if (timeoutRef.current) { + clearTimeout(timeoutRef.current); + } + handleClickStart(); + }; + const toggleMute = () => { if (video.current) { const muted = !video.current.muted; @@ -434,9 +468,17 @@ const Video: React.FC = ({ } }; + const handleTogglePlay = () => { + if (!isMobile) togglePlay(); + }; + const progress = (currentTime / duration) * 100; const playerStyle: React.CSSProperties = {}; + const startTimeout = () => { + timeoutRef.current = setTimeout(() => setHovered(false), 1000); + }; + if (inline && containerWidth) { width = containerWidth; const minSize = containerWidth / (16 / 9); @@ -481,10 +523,13 @@ const Video: React.FC = ({ return (
@@ -506,7 +551,7 @@ const Video: React.FC = ({ })} width={width} height={height || DEFAULT_HEIGHT} - onClick={togglePlay} + onClick={handleTogglePlay} onKeyDown={handleVideoKeyDown} onPlay={handlePlay} onPause={handlePause} @@ -516,7 +561,10 @@ const Video: React.FC = ({ onVolumeChange={handleVolumeChange} /> -
+
= ({
= ({ />
@@ -628,4 +676,4 @@ const Video: React.FC = ({ ); }; -export default Video; +export default Video; \ No newline at end of file From 42a28a053352d985ef07e4d54e6a45cd7c68d24a Mon Sep 17 00:00:00 2001 From: danidfra Date: Thu, 31 Oct 2024 18:14:59 -0300 Subject: [PATCH 2/2] Remove unnecessary comment --- src/features/video/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/features/video/index.tsx b/src/features/video/index.tsx index c9f1fa966..845c50dd5 100644 --- a/src/features/video/index.tsx +++ b/src/features/video/index.tsx @@ -563,7 +563,6 @@ const Video: React.FC = ({