11import type { VideoPlayer } from 'expo-video' ;
2- import React , { useCallback , useContext , useMemo , useRef , useState } from 'react' ;
2+ import React , { useCallback , useContext , useEffect , useMemo , useRef , useState } from 'react' ;
33import { useSession } from '@components/OnyxListItemProvider' ;
44import type { PopoverMenuItem } from '@components/PopoverMenu' ;
55import { useMemoizedLazyExpensifyIcons } from '@hooks/useLazyAsset' ;
@@ -9,6 +9,7 @@ import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
99import fileDownload from '@libs/fileDownload' ;
1010import CONST from '@src/CONST' ;
1111import type ChildrenProps from '@src/types/utils/ChildrenProps' ;
12+ import { usePlaybackStateContext } from './PlaybackContext' ;
1213import type { PlaybackSpeed , VideoPopoverMenuActionsContextType , VideoPopoverMenuStateContextType } from './types' ;
1314
1415const VideoPopoverMenuStateContext = React . createContext < VideoPopoverMenuStateContextType | null > ( null ) ;
@@ -17,6 +18,7 @@ const VideoPopoverMenuActionsContext = React.createContext<VideoPopoverMenuActio
1718function VideoPopoverMenuContextProvider ( { children} : ChildrenProps ) {
1819 const icons = useMemoizedLazyExpensifyIcons ( [ 'Checkmark' , 'Download' , 'Meter' ] as const ) ;
1920 const { translate} = useLocalize ( ) ;
21+ const { currentVideoPlayerRef, originalParent} = usePlaybackStateContext ( ) ;
2022 const [ source , setSource ] = useState ( '' ) ;
2123 const [ currentPlaybackSpeed , setCurrentPlaybackSpeed ] = useState < PlaybackSpeed > ( CONST . VIDEO_PLAYER . PLAYBACK_SPEEDS [ 3 ] ) ;
2224 const { isOffline} = useNetwork ( ) ;
@@ -39,6 +41,18 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
3941 [ videoPopoverMenuPlayerRef ] ,
4042 ) ;
4143
44+ // Apply stored playback speed when the active player changes (e.g. navigating from parent to thread).
45+ // Same pattern as VolumeContext which re-applies volume on originalParent change.
46+ useEffect ( ( ) => {
47+ if ( ! originalParent || ! currentVideoPlayerRef . current ) {
48+ return ;
49+ }
50+
51+ if ( currentVideoPlayerRef . current . playbackRate !== currentPlaybackSpeed ) {
52+ currentVideoPlayerRef . current . playbackRate = currentPlaybackSpeed ;
53+ }
54+ } , [ originalParent , currentPlaybackSpeed ] ) ;
55+
4256 const updateVideoPopoverMenuPlayerRef = ( videoPlayer : VideoPlayer | null ) => {
4357 videoPopoverMenuPlayerRef . current = videoPlayer ;
4458 } ;
0 commit comments