Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

VideoAttachmentMenu.tsx

53 lines1.8 KB

1import type { ReactElement } from "react";
2import { Platform, type PressableProps } from "react-native";
3​
4import { ControlPillMenu } from "./ControlPill";
5import { PresentationSource } from "./NativePresentation";
6​
7export function VideoAttachmentMenu(props: {
8 readonly sourceIdentifier: string;
9 readonly onOpen: () => void;
10 readonly onShare?: () => void;
11 readonly disabled?: boolean;
12 readonly children: ReactElement<PressableProps>;
13}) {
14 return (
15 <PresentationSource
16 identifier={props.sourceIdentifier}
17 accessible={Platform.OS === "ios"}
18 accessibilityRole="button"
19 accessibilityLabel={props.children.props.accessibilityLabel}
20 accessibilityHint={props.children.props.accessibilityHint}
21 accessibilityState={{ disabled: props.disabled ?? false }}
22 onAccessibilityTap={() => {
23 if (!props.disabled) props.onOpen();
24 }}
25 accessibilityActions={props.onShare ? [{ name: "share", label: "Save or share video" }] : []}
26 onAccessibilityAction={({ nativeEvent }) => {
27 if (nativeEvent.actionName === "share" && !props.disabled) props.onShare?.();
28 }}
29 >
30 {Platform.OS === "ios" && props.onShare ? (
31 <ControlPillMenu
32 shouldOpenOnLongPress
33 style={{ alignSelf: "flex-start" }}
34 actions={[
35 {
36 id: "share",
37 title: "Save or share video",
38 image: "square.and.arrow.up",
39 attributes: { disabled: props.disabled ?? false },
40 },
41 ]}
42 onPressAction={({ nativeEvent }) => {
43 if (nativeEvent.event === "share") props.onShare?.();
44 }}
45 >
46 {props.children}
47 </ControlPillMenu>
48 ) : (
49 props.children
50 )}
51 </PresentationSource>
52 );