Open History to see the last commit
1import type { MenuAction } from "@react-native-menu/menu";
2import { Pressable } from "react-native";
3
4import { SymbolView } from "./AppSymbol";
5import { ControlPillMenu } from "./ControlPill";
6
7const ATTACHMENT_MENU_ACTIONS: MenuAction[] = [
8 { id: "photos", title: "Photo Library", image: "photo" },
9 { id: "files", title: "Choose Files", image: "folder" },
10];
11
12export function ComposerAttachmentButton(props: {
13 readonly disabled?: boolean;
14 readonly supportsFiles: boolean;
15 readonly onPickMedia: () => Promise<void>;
16 readonly onPickFiles: () => Promise<void>;
17}) {
18 const button = (
19 <Pressable
20 accessibilityLabel="Add attachment"
21 accessibilityRole="button"
22 accessibilityState={{ disabled: props.disabled }}
23 className="size-[44px] shrink-0 items-center justify-center rounded-full active:opacity-70 disabled:opacity-50"
24 disabled={props.disabled}
25 onPress={props.supportsFiles ? undefined : () => void props.onPickMedia()}
26 >
27 <SymbolView
28 name="plus"
29 size={20}
30 weight="regular"
31 tintColorClassName="accent-icon"
32 type="monochrome"
33 />
34 </Pressable>
35 );
36
37 if (props.disabled || !props.supportsFiles) {
38 return button;
39 }
40
41 return (
42 <ControlPillMenu
43 accessible
44 accessibilityLabel="Add attachment"
45 accessibilityRole="button"
46 actions={ATTACHMENT_MENU_ACTIONS}
47 onPressAction={({ nativeEvent }) => {
48 if (nativeEvent.event === "photos") {
49 void props.onPickMedia();
50 } else if (nativeEvent.event === "files") {
51 void props.onPickFiles();
52 }
53 }}
54 >
55 {button}
56 </ControlPillMenu>
57 );
58}