Open History to see the last commit
1import { MenuView } from "@react-native-menu/menu";
2import type { ReactElement } from "react";
3import { Platform, View, type PressableProps } from "react-native";
4
5import type { useMediaActions } from "../lib/mediaActions";
6import { SymbolView } from "./AppSymbol";
7import { ControlPillMenu } from "./ControlPill";
8
9export function MediaActionsMenu(props: {
10 readonly media: ReturnType<typeof useMediaActions>;
11 readonly inModal?: boolean;
12 readonly children?: ReactElement<PressableProps>;
13}) {
14 if (props.media.actions.length === 0) return props.children ?? null;
15 // Android's normal anchored menu lives in the app-root portal, behind native modals.
16 const nativeAndroidMenu = props.inModal && Platform.OS === "android";
17 const Menu = nativeAndroidMenu ? MenuView : ControlPillMenu;
18 return (
19 <Menu
20 title={props.media.title}
21 shouldOpenOnLongPress={props.children !== undefined}
22 actions={props.media.actions.map(({ id, title, disabled }) => ({
23 id,
24 title,
25 attributes: { disabled: disabled ?? false },
26 }))}
27 onPressAction={({ nativeEvent }) => {
28 props.media.actions.find(({ id }) => id === nativeEvent.event)?.run();
29 }}
30 >
31 {props.children ?? (
32 <View
33 accessible
34 accessibilityRole="button"
35 accessibilityLabel="Media actions"
36 className="min-h-11 min-w-11 items-center justify-center rounded-md bg-black/60"
37 >
38 <SymbolView name="ellipsis" size={20} tintColor="#ffffff" type="monochrome" />
39 </View>
40 )}
41 </Menu>
42 );
43}