forked from Ninjalama/streamyfin_mirror
Co-authored-by: lostb1t <coding-mosses0z@icloud.com> Co-authored-by: Fredrik Burmester <fredrik.burmester@gmail.com> Co-authored-by: Gauvain <68083474+Gauvino@users.noreply.github.com> Co-authored-by: Gauvino <uruknarb20@gmail.com> Co-authored-by: storm1er <le.storm1er@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Chris <182387676+whoopsi-daisy@users.noreply.github.com> Co-authored-by: arch-fan <55891793+arch-fan@users.noreply.github.com> Co-authored-by: Alex Kim <alexkim@Alexs-MacBook-Pro.local>
94 lines
2.9 KiB
TypeScript
94 lines
2.9 KiB
TypeScript
import type { MediaSourceInfo } from "@jellyfin/sdk/lib/generated-client/models";
|
|
import { useMemo } from "react";
|
|
import { Platform, TouchableOpacity, View } from "react-native";
|
|
import { tc } from "@/utils/textTools";
|
|
|
|
const DropdownMenu = !Platform.isTV ? require("zeego/dropdown-menu") : null;
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
import { Text } from "./common/Text";
|
|
|
|
interface Props extends React.ComponentProps<typeof View> {
|
|
source?: MediaSourceInfo;
|
|
onChange: (value: number) => void;
|
|
selected?: number | undefined;
|
|
}
|
|
|
|
export const SubtitleTrackSelector: React.FC<Props> = ({
|
|
source,
|
|
onChange,
|
|
selected,
|
|
...props
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
const subtitleStreams = useMemo(() => {
|
|
return source?.MediaStreams?.filter((x) => x.Type === "Subtitle");
|
|
}, [source]);
|
|
|
|
const selectedSubtitleSteam = useMemo(
|
|
() => subtitleStreams?.find((x) => x.Index === selected),
|
|
[subtitleStreams, selected],
|
|
);
|
|
|
|
if (Platform.isTV || subtitleStreams?.length === 0) return null;
|
|
|
|
return (
|
|
<View
|
|
className='flex col shrink justify-start place-self-start items-start'
|
|
style={{
|
|
minWidth: 60,
|
|
maxWidth: 200,
|
|
}}
|
|
>
|
|
<DropdownMenu.Root>
|
|
<DropdownMenu.Trigger>
|
|
<View className='flex flex-col ' {...props}>
|
|
<Text numberOfLines={1} className='opacity-50 mb-1 text-xs'>
|
|
{t("item_card.subtitles")}
|
|
</Text>
|
|
<TouchableOpacity className='bg-neutral-900 h-10 rounded-xl border-neutral-800 border px-3 py-2 flex flex-row items-center justify-between'>
|
|
<Text className=' '>
|
|
{selectedSubtitleSteam
|
|
? tc(selectedSubtitleSteam?.DisplayTitle, 7)
|
|
: t("item_card.none")}
|
|
</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
</DropdownMenu.Trigger>
|
|
<DropdownMenu.Content
|
|
loop={true}
|
|
side='bottom'
|
|
align='start'
|
|
alignOffset={0}
|
|
avoidCollisions={true}
|
|
collisionPadding={8}
|
|
sideOffset={8}
|
|
>
|
|
<DropdownMenu.Label>Subtitle tracks</DropdownMenu.Label>
|
|
<DropdownMenu.Item
|
|
key={"-1"}
|
|
onSelect={() => {
|
|
onChange(-1);
|
|
}}
|
|
>
|
|
<DropdownMenu.ItemTitle>None</DropdownMenu.ItemTitle>
|
|
</DropdownMenu.Item>
|
|
{subtitleStreams?.map((subtitle, idx: number) => (
|
|
<DropdownMenu.Item
|
|
key={idx.toString()}
|
|
onSelect={() => {
|
|
if (subtitle.Index !== undefined && subtitle.Index !== null)
|
|
onChange(subtitle.Index);
|
|
}}
|
|
>
|
|
<DropdownMenu.ItemTitle>
|
|
{subtitle.DisplayTitle}
|
|
</DropdownMenu.ItemTitle>
|
|
</DropdownMenu.Item>
|
|
))}
|
|
</DropdownMenu.Content>
|
|
</DropdownMenu.Root>
|
|
</View>
|
|
);
|
|
};
|