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

android-menu-sections.ts

27 lines988 Bytes

1import type { MenuAction } from "@react-native-menu/menu";
2​
3interface AndroidMenuEntry {
4 readonly action: MenuAction;
5 readonly dividerBefore: boolean;
6}
7​
8export function flattenInlineMenuSections(actions: readonly MenuAction[]) {
9 const entries: AndroidMenuEntry[] = [];
10 let previousWasInlineGroup = false;
11 for (const action of actions) {
12 if (action.attributes?.hidden === true) continue;
13 if (action.displayInline === true && action.subactions) {
14 const visibleChildren = action.subactions.filter(
15 (child) => child.attributes?.hidden !== true,
16 );
17 for (const [index, child] of visibleChildren.entries()) {
18 entries.push({ action: child, dividerBefore: index === 0 && entries.length > 0 });
19 }
20 if (visibleChildren.length > 0) previousWasInlineGroup = true;
21 continue;
22 }
23 entries.push({ action, dividerBefore: previousWasInlineGroup && entries.length > 0 });
24 previousWasInlineGroup = false;
25 }
26 return entries;