[Video] Fix fullscreen on Chrome (#5246)

This commit is contained in:
Samuel Newman 2024-09-10 06:37:57 +01:00 committed by GitHub
parent 0f6be244a6
commit 66239ba11d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 67 additions and 30 deletions

View file

@ -12,6 +12,7 @@ import {
VideoNotFoundError,
} from '#/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb'
import {atoms as a} from '#/alf'
import {useFullscreen} from '#/components/hooks/useFullscreen'
import {ErrorBoundary} from '../ErrorBoundary'
import {useActiveVideoWeb} from './ActiveVideoWebContext'
import * as VideoFallback from './VideoEmbedInner/VideoFallback'
@ -106,6 +107,8 @@ function ViewportObserver({
}) {
const ref = useRef<HTMLDivElement>(null)
const [nearScreen, setNearScreen] = useState(false)
const [isFullscreen] = useFullscreen()
const [nearScreenOrFullscreen, setNearScreenOrFullscreen] = useState(false)
// Send position when scrolling. This is done with an IntersectionObserver
// observing a div of 100vh height
@ -135,9 +138,17 @@ function ViewportObserver({
}
}, [isAnyViewActive, sendPosition])
// disguesting effect - it should be `nearScreen` except when fullscreen
// when it should be whatever it was before fullscreen changed
useEffect(() => {
if (!isFullscreen) {
setNearScreenOrFullscreen(nearScreen)
}
}, [isFullscreen, nearScreen])
return (
<View style={[a.flex_1, a.flex_row]}>
{nearScreen && children}
{nearScreenOrFullscreen && children}
<div
ref={ref}
style={{