1import type { MenuAction } from "@react-native-menu/menu";
2
3// MenuView's iOS bridge treats an omitted imageColor as transparent.
4export function withMenuActionIconColors(
5 actions: readonly MenuAction[],
6 colors: {
7 readonly icon: MenuAction["imageColor"];
8 readonly destructiveIcon: MenuAction["imageColor"];
9 },
10): MenuAction[] {
11 return actions.map((action) => ({
12 ...action,
13 ...(action.image
14 ? {
15 imageColor:
16 action.imageColor ??
17 (action.attributes?.destructive ? colors.destructiveIcon : colors.icon),
18 }
19 : {}),
20 ...(action.subactions
21 ? { subactions: withMenuActionIconColors(action.subactions, colors) }
22 : {}),
23 }));
24}