diff --git a/components/downloads/EpisodeCard.tsx b/components/downloads/EpisodeCard.tsx index a303caed..456563db 100644 --- a/components/downloads/EpisodeCard.tsx +++ b/components/downloads/EpisodeCard.tsx @@ -1,8 +1,11 @@ import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import * as Haptics from "expo-haptics"; -import React, { useCallback } from "react"; +import React, { useCallback, useRef } from "react"; import { TouchableOpacity } from "react-native"; -import * as ContextMenu from "zeego/context-menu"; +import { + ActionSheetProvider, + useActionSheet, +} from "@expo/react-native-action-sheet"; import { useFileOpener } from "@/hooks/useDownloadedFileOpener"; import { Text } from "../common/Text"; @@ -13,13 +16,14 @@ interface EpisodeCardProps { } /** - * EpisodeCard component displays an episode with context menu options. + * EpisodeCard component displays an episode with action sheet options. * @param {EpisodeCardProps} props - The component props. * @returns {React.ReactElement} The rendered EpisodeCard component. */ export const EpisodeCard: React.FC = ({ item }) => { const { deleteFile } = useDownload(); const { openFile } = useFileOpener(); + const { showActionSheetWithOptions } = useActionSheet(); const handleOpenFile = useCallback(() => { openFile(item); @@ -35,43 +39,48 @@ export const EpisodeCard: React.FC = ({ item }) => { } }, [deleteFile, item.Id]); - const contextMenuOptions = [ - { - label: "Delete", - onSelect: handleDeleteFile, - destructive: true, - }, - ]; + const showActionSheet = useCallback(() => { + const options = ["Delete", "Cancel"]; + const destructiveButtonIndex = 0; + const cancelButtonIndex = 1; + + showActionSheetWithOptions( + { + options, + cancelButtonIndex, + destructiveButtonIndex, + }, + (selectedIndex) => { + switch (selectedIndex) { + case destructiveButtonIndex: + // Delete + handleDeleteFile(); + break; + case cancelButtonIndex: + // Cancelled + break; + } + } + ); + }, [showActionSheetWithOptions, handleDeleteFile]); return ( - - - - {item.Name} - Episode {item.IndexNumber} - - - - {contextMenuOptions.map((option) => ( - - - {option.label} - - - ))} - - + + {item.Name} + Episode {item.IndexNumber} + ); }; + +// Wrap the parent component with ActionSheetProvider +export const EpisodeCardWithActionSheet: React.FC = ( + props +) => ( + + + +); diff --git a/components/downloads/MovieCard.tsx b/components/downloads/MovieCard.tsx index 69eeae4f..8be14bf8 100644 --- a/components/downloads/MovieCard.tsx +++ b/components/downloads/MovieCard.tsx @@ -2,7 +2,10 @@ import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import * as Haptics from "expo-haptics"; import React, { useCallback } from "react"; import { TouchableOpacity, View } from "react-native"; -import * as ContextMenu from "zeego/context-menu"; +import { + ActionSheetProvider, + useActionSheet, +} from "@expo/react-native-action-sheet"; import { runtimeTicksToMinutes } from "@/utils/time"; import { Text } from "../common/Text"; @@ -15,13 +18,14 @@ interface MovieCardProps { } /** - * MovieCard component displays a movie with context menu options. + * MovieCard component displays a movie with action sheet options. * @param {MovieCardProps} props - The component props. * @returns {React.ReactElement} The rendered MovieCard component. */ export const MovieCard: React.FC = ({ item }) => { const { deleteFile } = useDownload(); const { openFile } = useFileOpener(); + const { showActionSheetWithOptions } = useActionSheet(); const handleOpenFile = useCallback(() => { openFile(item); @@ -37,48 +41,51 @@ export const MovieCard: React.FC = ({ item }) => { } }, [deleteFile, item.Id]); - const contextMenuOptions = [ - { - label: "Delete", - onSelect: handleDeleteFile, - destructive: true, - }, - ]; + const showActionSheet = useCallback(() => { + const options = ["Delete", "Cancel"]; + const destructiveButtonIndex = 0; + const cancelButtonIndex = 1; + + showActionSheetWithOptions( + { + options, + cancelButtonIndex, + destructiveButtonIndex, + }, + (selectedIndex) => { + switch (selectedIndex) { + case destructiveButtonIndex: + // Delete + handleDeleteFile(); + break; + case cancelButtonIndex: + // Cancelled + break; + } + } + ); + }, [showActionSheetWithOptions, handleDeleteFile]); return ( - - - - {item.Name} - - {item.ProductionYear} - - {runtimeTicksToMinutes(item.RunTimeTicks)} - - - - - - {contextMenuOptions.map((option) => ( - - - {option.label} - - - ))} - - + + {item.Name} + + {item.ProductionYear} + + {runtimeTicksToMinutes(item.RunTimeTicks)} + + + ); }; + +// Wrap the parent component with ActionSheetProvider +export const MovieCardWithActionSheet: React.FC = (props) => ( + + + +);