(actions: Action[] | Action[][], platform: Platform)
| 54 | * because its native menu doesn't render inline groups. |
| 55 | */ |
| 56 | export const buildMenu = (actions: Action[] | Action[][], platform: Platform): { items: ContextMenuAction[]; ids: IdNode[] } => { |
| 57 | const items: ContextMenuAction[] = []; |
| 58 | const ids: IdNode[] = []; |
| 59 | |
| 60 | if (platform === 'ios') { |
| 61 | for (const group of actions) { |
| 62 | if (Array.isArray(group)) { |
| 63 | const inline = group.map(a => mapLeaf(a, platform)).filter((r): r is { item: ContextMenuAction; idNode: IdNode } => r !== null); |
| 64 | if (inline.length === 0) continue; |
| 65 | items.push({ |
| 66 | title: '', |
| 67 | actions: inline.map(r => r.item), |
| 68 | inlineChildren: true, |
| 69 | } as ContextMenuAction); |
| 70 | // Synthetic inline group: no id of its own, only carries children. |
| 71 | ids.push({ children: inline.map(r => r.idNode) }); |
| 72 | } else { |
| 73 | const r = mapLeaf(group, platform); |
| 74 | if (r) { |
| 75 | items.push(r.item); |
| 76 | ids.push(r.idNode); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | return { items, ids }; |
| 81 | } |
| 82 | |
| 83 | for (const action of actions.flat()) { |
| 84 | const r = mapLeaf(action, platform); |
| 85 | if (r) { |
| 86 | items.push(r.item); |
| 87 | ids.push(r.idNode); |
| 88 | } |
| 89 | } |
| 90 | return { items, ids }; |
| 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * Resolve the original Action.id for a press event by walking the id-tree |
no test coverage detected