Open History to see the last commit
1import { Platform, Pressable, View, type StyleProp, type ViewStyle } from "react-native";
2
3import { cn } from "../lib/cn";
4import type { DraftComposerFileAttachment } from "../lib/composerImages";
5import { useMediaActions, type MediaActionsSource } from "../lib/mediaActions";
6import { SymbolView } from "./AppSymbol";
7import { AppText } from "./AppText";
8import { MediaActionsMenu } from "./MediaActionsMenu";
9import { PresentationSource } from "./NativePresentation";
10import { VideoThumbnailImage } from "./VideoThumbnailImage";
11
12export function VideoAttachmentTile(props: {
13 readonly name: string;
14 readonly sourceIdentifier: string;
15 readonly thumbnailSource: string | DraftComposerFileAttachment | null;
16 readonly actionsSource?: MediaActionsSource;
17 readonly compact?: boolean;
18 readonly onPress: (sourceIdentifier: string) => void;
19 readonly disabled?: boolean;
20 readonly className?: string;
21 readonly style?: StyleProp<ViewStyle>;
22}) {
23 const mediaActions = useMediaActions(props.disabled ? undefined : props.actionsSource);
24 const hasActions = mediaActions.actions.length > 0;
25 return (
26 <PresentationSource
27 identifier={props.sourceIdentifier}
28 accessible={Platform.OS === "ios"}
29 accessibilityRole="button"
30 accessibilityLabel={`Play ${props.name}`}
31 accessibilityState={{ disabled: props.disabled ?? false }}
32 onAccessibilityTap={() => {
33 if (!props.disabled) props.onPress(props.sourceIdentifier);
34 }}
35 accessibilityActions={mediaActions.actions.map(({ id, title }) => ({
36 name: id,
37 label: title,
38 }))}
39 onAccessibilityAction={({ nativeEvent }) => {
40 if (props.disabled) return;
41 mediaActions.actions.find(({ id }) => id === nativeEvent.actionName)?.run();
42 }}
43 >
44 <MediaActionsMenu media={mediaActions}>
45 <Pressable
46 accessibilityRole="button"
47 accessibilityLabel={`Play ${props.name}`}
48 accessibilityHint={hasActions ? "Touch and hold for media actions" : undefined}
49 accessibilityState={{ disabled: props.disabled ?? false }}
50 disabled={props.disabled}
51 onPress={() => props.onPress(props.sourceIdentifier)}
52 className={cn("items-center justify-center overflow-hidden bg-black/80", props.className)}
53 style={props.style}
54 >
55 <VideoThumbnailImage cacheKey={props.sourceIdentifier} source={props.thumbnailSource} />
56 <View
57 className={cn(
58 "items-center justify-center rounded-full bg-black/45",
59 props.compact ? "size-6" : "size-12",
60 )}
61 >
62 <SymbolView
63 name="play"
64 size={props.compact ? 15 : 24}
65 tintColor="#ffffff"
66 type="monochrome"
67 />
68 </View>
69 {!props.compact ? (
70 <View className="absolute inset-x-0 bottom-0 bg-black/55 px-2 py-1.5">
71 <AppText className="text-center text-xs text-white" numberOfLines={1}>
72 {props.name}
73 </AppText>
74 </View>
75 ) : null}
76 </Pressable>
77 </MediaActionsMenu>
78 </PresentationSource>
79 );
80}