Open History to see the last commit
1import { SymbolView } from "expo-symbols";
2import { Image, Pressable, ScrollView, View } from "react-native";
3import { useThemeColor } from "../lib/useThemeColor";
4
5import type { DraftComposerImageAttachment } from "../lib/composerImages";
6
7export interface ComposerAttachmentStripProps {
8 /** Attachment images to display. */
9 readonly attachments: ReadonlyArray<DraftComposerImageAttachment>;
10 /** Called when the user taps the remove button on an image. */
11 readonly onRemove: (imageId: string) => void;
12 /** Called when the user taps on an image thumbnail to preview it. */
13 readonly onPressImage?: (previewUri: string) => void;
14 /** Image thumbnail size in points. Defaults to 72. */
15 readonly imageSize?: number;
16 /** Border radius of each image thumbnail. Defaults to 16. */
17 readonly imageBorderRadius?: number;
18 /** Whether the remove button should sit in its own gutter instead of overlapping the image. */
19 readonly removeButtonPlacement?: "overlay" | "gutter";
20}
21
22/**
23 * A horizontally-scrollable strip of image attachment thumbnails with remove
24 * buttons. Used by both the thread composer and the new-task draft screen.
25 */
26export function ComposerAttachmentStrip(props: ComposerAttachmentStripProps) {
27 const subtleBg = useThemeColor("--color-subtle");
28 const size = props.imageSize ?? 72;
29 const radius = props.imageBorderRadius ?? 16;
30 const removeButtonPlacement = props.removeButtonPlacement ?? "overlay";
31 const removeButtonGutter = removeButtonPlacement === "gutter" ? 10 : 0;
32
33 if (props.attachments.length === 0) {
34 return null;
35 }
36
37 return (
38 <ScrollView
39 horizontal
40 showsHorizontalScrollIndicator={false}
41 keyboardShouldPersistTaps="always"
42 style={{ flexGrow: 0 }}
43 >
44 <View style={{ flexDirection: "row", gap: 10 }}>
45 {props.attachments.map((image) => (
46 <View
47 key={image.id}
48 style={{
49 position: "relative",
50 paddingTop: removeButtonGutter,
51 paddingRight: removeButtonGutter,
52 }}
53 >
54 <Pressable
55 onPress={props.onPressImage ? () => props.onPressImage!(image.previewUri) : undefined}
56 >
57 <Image
58 source={{ uri: image.previewUri }}
59 style={{
60 width: size,
61 height: size,
62 borderRadius: radius,
63 backgroundColor: subtleBg,
64 }}
65 resizeMode="cover"
66 />
67 </Pressable>
68 <Pressable
69 style={{
70 position: "absolute",
71 top: removeButtonPlacement === "gutter" ? 0 : 4,
72 right: removeButtonPlacement === "gutter" ? 0 : 4,
73 width: 22,
74 height: 22,
75 borderRadius: 11,
76 backgroundColor: "rgba(0,0,0,0.55)",
77 alignItems: "center",
78 justifyContent: "center",
79 }}
80 hitSlop={6}
81 onPress={() => props.onRemove(image.id)}
82 >
83 <SymbolView
84 name="xmark"
85 size={9}
86 tintColor="#ffffff"
87 type="monochrome"
88 weight="bold"
89 />
90 </Pressable>
91 </View>
92 ))}
93 </View>
94 </ScrollView>
95 );
96}