import { MenuView } from "@react-native-menu/menu"; import type { ReactElement } from "react"; import { Platform, View, type PressableProps, type StyleProp, type ViewStyle } from "react-native"; import type { useMediaActions } from "../lib/mediaActions"; import { SymbolView } from "./AppSymbol"; import { ControlPillMenu } from "./ControlPill"; export function MediaActionsMenu(props: { readonly media: ReturnType; readonly inModal?: boolean; readonly children?: ReactElement; readonly style?: StyleProp; }) { if (props.media.actions.length === 0) return props.children ?? null; // Android's normal anchored menu lives in the app-root portal, behind native modals. const nativeAndroidMenu = props.inModal && Platform.OS === "android"; const Menu = nativeAndroidMenu ? MenuView : ControlPillMenu; return ( ({ id, title, attributes: { disabled: disabled ?? false }, }))} onPressAction={({ nativeEvent }) => { props.media.actions.find(({ id }) => id === nativeEvent.event)?.run(); }} > {props.children ?? ( )} ); }