diff --git a/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx b/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx index d972fc2d53..721c1ba22a 100644 --- a/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx +++ b/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useRef, useState} from 'react' +import React, {useCallback, useEffect, useRef, useState} from 'react' import {View} from 'react-native' import Animated, {FadeIn, FadeOut} from 'react-native-reanimated' import {msg} from '@lingui/macro' @@ -86,6 +86,7 @@ export function VideoPlayer({ onScreen: boolean }) { const [hls] = useState(() => new Hls()) + const containerRef = useRef(null) const ref = useRef(null) const [focused, setFocused] = useState(false) @@ -115,6 +116,12 @@ export function VideoPlayer({ } }, [source, hls]) + const enterFullscreen = useCallback(() => { + if (containerRef.current) { + containerRef.current.requestFullscreen() + } + }, []) + return ( - - ) } @@ -164,6 +174,7 @@ function Controls({ focused, setFocused, onScreen, + enterFullscreen, }: { videoRef: React.RefObject active: boolean @@ -171,6 +182,7 @@ function Controls({ focused: boolean setFocused: (focused: boolean) => void onScreen: boolean + enterFullscreen: () => void }) { const {play, pause, playing, muted, togglePlayPause, currentTime, duration} = useVideoUtils(videoRef) @@ -217,49 +229,55 @@ function Controls({ onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}> {hovered && ( - - - - - {/* TODO: find workaround for iOS Safari */} - - + <> + + + + + {/* TODO: find workaround for iOS Safari */} + + + )} {(hovered || !focused) && ( ) { if (!ref.current) return let current = ref.current + // Initial values + setCurrentTime(current.currentTime || 0) + setDuration(current.duration || 0) + setCanPlay(current.readyState >= HTMLMediaElement.HAVE_FUTURE_DATA) + setMuted(current.muted) + setPlaying(!current.paused) + const handleTimeUpdate = () => { if (!current) return setCurrentTime(current.currentTime || 0) @@ -384,11 +409,7 @@ function useVideoUtils(ref: React.RefObject) { } const togglePlayPause = () => { - if (playing) { - play() - } else { - pause() - } + setPlaying(p => !p) } return {play, pause, togglePlayPause, duration, currentTime, playing, muted}