Skip to content

Commit

Permalink
update ref name
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbautistars12 committed Apr 26, 2024
1 parent 7ffafd7 commit 50b3cb4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/VideoPlayer/BaseVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function BaseVideoPlayer({
const isUploading = CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => url.startsWith(prefix));
const videoStateRef = useRef<AVPlaybackStatus | null>(null);
const {updateVolume} = useVolumeContext();
const {playerRef} = useVideoPopoverMenuContext();
const {videoPopoverMenuPlayerRef} = useVideoPopoverMenuContext();

const togglePlayCurrentVideo = useCallback(() => {
videoResumeTryNumber.current = 0;
Expand All @@ -95,7 +95,7 @@ function BaseVideoPlayer({

const showPopoverMenu = (event?: GestureResponderEvent | KeyboardEvent) => {
setIsPopoverVisible(true);
playerRef.current = videoPlayerRef.current;
videoPopoverMenuPlayerRef.current = videoPlayerRef.current;
if (!event || !('nativeEvent' in event)) {
return;
}
Expand Down
12 changes: 6 additions & 6 deletions src/components/VideoPlayerContexts/VideoPopoverMenuContext.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {AVPlaybackSourceObject} from 'expo-av';
import React, {useCallback, useContext, useMemo, useRef, useState} from 'react';
import * as Expensicons from '@components/Icon/Expensicons';
import type {PopoverMenuItem} from '@components/PopoverMenu';
Expand All @@ -10,7 +11,6 @@ import CONST from '@src/CONST';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import {usePlaybackContext} from './PlaybackContext';
import type {PlaybackSpeed, VideoPopoverMenuContext} from './types';
import { AVPlaybackSourceObject } from 'expo-av';

const Context = React.createContext<VideoPopoverMenuContext | null>(null);

Expand All @@ -20,7 +20,7 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
const [currentPlaybackSpeed, setCurrentPlaybackSpeed] = useState<PlaybackSpeed>(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS[2]);
const {isOffline} = useNetwork();
const isLocalFile = currentlyPlayingURL && CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => currentlyPlayingURL.startsWith(prefix));
const playerRef = useRef<VideoWithOnFullScreenUpdate | null>(null);
const videoPopoverMenuPlayerRef = useRef<VideoWithOnFullScreenUpdate | null>(null);

const updatePlaybackSpeed = useCallback(
(speed: PlaybackSpeed) => {
Expand All @@ -31,12 +31,12 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
);

const downloadAttachment = useCallback(() => {
if (playerRef.current === null) {
if (videoPopoverMenuPlayerRef.current === null) {
return;
}
const sourceURI = addEncryptedAuthTokenToURL((playerRef.current.props.source as AVPlaybackSourceObject).uri);
const sourceURI = addEncryptedAuthTokenToURL((videoPopoverMenuPlayerRef.current.props.source as AVPlaybackSourceObject).uri);
fileDownload(sourceURI);
}, [playerRef]);
}, [videoPopoverMenuPlayerRef]);

const menuItems = useMemo(() => {
const items: PopoverMenuItem[] = [];
Expand Down Expand Up @@ -66,7 +66,7 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
return items;
}, [currentPlaybackSpeed, downloadAttachment, translate, updatePlaybackSpeed, isOffline, isLocalFile]);

const contextValue = useMemo(() => ({menuItems, playerRef, updatePlaybackSpeed}), [menuItems, playerRef, updatePlaybackSpeed]);
const contextValue = useMemo(() => ({menuItems, videoPopoverMenuPlayerRef, updatePlaybackSpeed}), [menuItems, videoPopoverMenuPlayerRef, updatePlaybackSpeed]);
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/VideoPlayerContexts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type VolumeContext = {

type VideoPopoverMenuContext = {
menuItems: PopoverMenuItem[];
playerRef: MutableRefObject<VideoWithOnFullScreenUpdate | null>;
videoPopoverMenuPlayerRef: MutableRefObject<VideoWithOnFullScreenUpdate | null>;
updatePlaybackSpeed: (speed: PlaybackSpeed) => void;
};

Expand Down

0 comments on commit 50b3cb4

Please sign in to comment.