Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix download option is shown for local file #56294

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/components/VideoPlayer/BaseVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import VideoPopoverMenu from '@components/VideoPopoverMenu';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import {canUseTouchScreen as canUseTouchScreenLib} from '@libs/DeviceCapabilities';
import CONST from '@src/CONST';
import shouldReplayVideo from './shouldReplayVideo';
import type {VideoPlayerProps, VideoWithOnFullScreenUpdate} from './types';
Expand Down Expand Up @@ -86,12 +86,12 @@ function BaseVideoPlayer({
const videoPlayerElementParentRef = useRef<View | HTMLDivElement | null>(null);
const videoPlayerElementRef = useRef<View | HTMLDivElement | null>(null);
const sharedVideoPlayerParentRef = useRef<View | HTMLDivElement | null>(null);
const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();
const canUseTouchScreen = canUseTouchScreenLib();
const isCurrentlyURLSet = currentlyPlayingURL === url;
const isUploading = CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => url.startsWith(prefix));
const videoStateRef = useRef<AVPlaybackStatus | null>(null);
const {updateVolume, lastNonZeroVolume} = useVolumeContext();
const {videoPopoverMenuPlayerRef, currentPlaybackSpeed, setCurrentPlaybackSpeed} = useVideoPopoverMenuContext();
const {videoPopoverMenuPlayerRef, currentPlaybackSpeed, setCurrentPlaybackSpeed, setSource: setPopoverMenuSource} = useVideoPopoverMenuContext();
const {source} = videoPopoverMenuPlayerRef.current?.props ?? {};
const shouldUseNewRate = typeof source === 'number' || !source || source.uri !== sourceURL;

Expand Down Expand Up @@ -163,6 +163,7 @@ function BaseVideoPlayer({
}
setIsPopoverVisible(true);
});
setPopoverMenuSource(url);
if (!event || !('nativeEvent' in event)) {
return;
}
Expand Down
18 changes: 7 additions & 11 deletions src/components/VideoPlayerContexts/VideoPopoverMenuContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import type {PopoverMenuItem} from '@components/PopoverMenu';
import type {VideoWithOnFullScreenUpdate} from '@components/VideoPlayer/types';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
import fileDownload from '@libs/fileDownload';
import CONST from '@src/CONST';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import {usePlaybackContext} from './PlaybackContext';
import type {PlaybackSpeed, VideoPopoverMenuContext} from './types';

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

function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
const {currentlyPlayingURL} = usePlaybackContext();
const {translate} = useLocalize();
const [source, setSource] = useState('');
const [currentPlaybackSpeed, setCurrentPlaybackSpeed] = useState<PlaybackSpeed>(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS[3]);
const {isOffline} = useNetwork();
const isLocalFile = currentlyPlayingURL && CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => currentlyPlayingURL.startsWith(prefix));
const isLocalFile = source && CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => source.startsWith(prefix));
const videoPopoverMenuPlayerRef = useRef<VideoWithOnFullScreenUpdate | null>(null);

const updatePlaybackSpeed = useCallback(
Expand All @@ -29,15 +29,11 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
);

const downloadAttachment = useCallback(() => {
if (videoPopoverMenuPlayerRef.current === null) {
return;
}
const {source} = videoPopoverMenuPlayerRef.current?.props ?? {};
if (typeof source === 'number' || !source) {
return;
}
fileDownload(source.uri);
}, [videoPopoverMenuPlayerRef]);
fileDownload(addEncryptedAuthTokenToURL(source));
}, [source]);

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

const contextValue = useMemo(
() => ({menuItems, videoPopoverMenuPlayerRef, currentPlaybackSpeed, updatePlaybackSpeed, setCurrentPlaybackSpeed}),
[menuItems, videoPopoverMenuPlayerRef, currentPlaybackSpeed, updatePlaybackSpeed, setCurrentPlaybackSpeed],
() => ({menuItems, videoPopoverMenuPlayerRef, currentPlaybackSpeed, updatePlaybackSpeed, setCurrentPlaybackSpeed, setSource}),
[menuItems, videoPopoverMenuPlayerRef, currentPlaybackSpeed, updatePlaybackSpeed, setCurrentPlaybackSpeed, setSource],
);
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/VideoPlayerContexts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type VideoPopoverMenuContext = {
currentPlaybackSpeed: PlaybackSpeed;
updatePlaybackSpeed: (speed: PlaybackSpeed) => void;
setCurrentPlaybackSpeed: (speed: PlaybackSpeed) => void;
setSource: (source: string) => void;
};

type FullScreenContext = {
Expand Down
Loading