Skip to content

Commit

Permalink
Merge pull request #40132 from KMichel1030/fix/issue-38720
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored Apr 19, 2024
2 parents dc2d8c2 + 6cb3222 commit e0a43be
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/VideoPlayer/BaseVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type {AVPlaybackStatus, VideoFullscreenUpdateEvent} from 'expo-av';
import {ResizeMode, Video, VideoFullscreenUpdate} from 'expo-av';
import type {MutableRefObject} from 'react';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import React, {useCallback, useEffect, useLayoutEffect, useRef, useState} from 'react';
import type {GestureResponderEvent} from 'react-native';
import {View} from 'react-native';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
Expand Down Expand Up @@ -194,6 +194,18 @@ function BaseVideoPlayer({
});
}, [currentVideoPlayerRef, handleFullscreenUpdate, handlePlaybackStatusUpdate]);

// use `useLayoutEffect` instead of `useEffect` because ref is null when unmount in `useEffect` hook
// ref url: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#effect-cleanup-timing
useLayoutEffect(
() => () => {
if (shouldUseSharedVideoElement || videoPlayerRef.current !== currentVideoPlayerRef.current) {
return;
}
currentVideoPlayerRef.current = null;
},
[currentVideoPlayerRef, shouldUseSharedVideoElement],
);

useEffect(() => {
if (!isUploading || !videoPlayerRef.current) {
return;
Expand Down

0 comments on commit e0a43be

Please sign in to comment.