Skip to content

fix: honor Ruby per-trigger item lists on the Cupertino ContextMenu - #74

Merged
AdamMusa merged 2 commits into
codex/engine-initializationfrom
fix/cupertino-context-menu-trigger-items
Nov 2, 2026
Merged

AdamMusa merged 2 commits into
codex/engine-initializationfrom
fix/cupertino-context-menu-trigger-items

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Depends on #40. This branch is stacked on #40's head (ffda09c), because it changes the item selection and payload that #40 introduced in cupertino_context_menu.dart. The only new commit is a262682.

Coordinated with #71 (iOS ContextMenu.open replies with an immediate UnsupportedError). This PR touches only build() and the payload helpers. #71 adds the invoke listener at the top of the state class. git merge-tree is clean. I also merged #71 into this branch in a scratch worktree and ran its tests with these: ruby_context_menu_trigger_items_test, ruby_context_menu_events_test (#40) and ruby_context_menu_open_test (#71), 12 tests, all passed. Because #71 makes open fail on iOS, the long press is the only way to reach the menu on iOS. That is why the last-resort rule below exists.

Summary

Ruby's ContextMenu declares items, primary_items, secondary_items and tertiary_items, plus primary_trigger, secondary_trigger and tertiary_trigger. On Material, each mouse button opens its own list using its trigger: by default primary is disabled and secondary and tertiary are down. A button with an empty list falls back to items, then actions.

The iOS renderer read only actions/items. The per-button lists were ignored, and a menu configured only with them rendered an error box on iOS.

Decision: what the iOS long press means

iOS has a single context-menu gesture, the long press (CupertinoContextMenu, the counterpart of UIKit's UIContextMenuInteraction). It stands in for the pointer button a desktop user would use for the same menu:

  1. primary, when primary_trigger is long_press, because the author bound this exact gesture;
  2. otherwise secondary, the context click, which is how a long press maps onto desktop right-click, unless secondary_trigger is disabled;
  3. otherwise primary.

The menu then shows that button's list, else items, else actions, exactly Material's fallback. As a last resort, if those are all empty but another per-button list has items (for example only tertiary_items, a middle click with no touch equivalent), the long press shows it. iOS has no other way to open the menu, so the menu stays reachable instead of becoming an error box. The error remains only when every list is empty.

tertiary_items is therefore used on iOS only through this last resort. A primary_trigger: "down" (tap-to-open) has no native equivalent, so a primary list bound to a tap is reachable by long press only through the last resort.

Payload

select and dismiss keep #40's Material keys. b is now the button the long press stood for, and tr is that button's configured trigger, spelled as Material reports it (down, longPress, disabled). Previously these were hard-coded to primary and longPress. With default triggers, an iOS long press now reports the same b: "secondary", tr: "down" as a right-click on Material. g and l stay null.

Tests

New test/widgets/ruby_context_menu_trigger_items_test.dart (6 tests):

  • Default triggers with items only: the long press shows items. select sends {b: secondary, tr: down, id: 11, idx: 1, ic: 2}.
  • All lists given: the long press shows secondary_items.
  • primary_trigger: "long_press": shows primary_items, with b: primary, tr: longPress.
  • secondary_trigger: "disabled": falls back to items.
  • Only tertiary_items: no error box, the long press shows it, b: tertiary.
  • Cross-design: a Material right-click on secondary_items, then "Rename", gives the same {b, tr, id, idx, ic} as the iOS long press, then "Rename".

Five of the six failed before this change. The disabled-secondary case already showed items, so it is kept as a guard. #40's tests still pass.

verify_pr.sh (branch head, which includes #40): flutter test +704, all passed (695 baseline + 3 from #40 + 6 new). flutter analyze lib test found no issues. Flutter 3.41.2. Merges cleanly with the current base fced255.

Wave-3 item 2

@AdamMusa
AdamMusa merged commit bf62bf8 into codex/engine-initialization Nov 2, 2026
AdamMusa pushed a commit that referenced this pull request Nov 3, 2026
Review of #74 found two Material ContextMenu gaps. Both are already
closed in the merged code; this pins the one that had no test.

- An items-only menu (Ruby's ContextMenu sends `items` and the
  per-trigger lists, never `actions`): #78 made the Material renderer
  fall back to `items` before `actions` for every trigger and for a
  programmatic open, and ruby_material_context_menu_items_test.dart
  covers the right-click case.
- `primary_trigger: "long_press"`: parseContextMenuTrigger goes through
  the shared parseEnum, which #63 made compare names without case or
  underscores, so Material accepts Ruby's spelling as iOS does. Nothing
  tested it on Material.

ruby_context_menu_trigger_items_test.dart now long-presses a menu with
`primary_trigger` "long_press" and "longPress" on iOS and Android: each
shows `primary_items` (not `secondary_items`) and selecting reports
b: primary, tr: longPress. With parseEnum as it was before #63 the
Android "long_press" case fails (no menu opens). Context menu tests and
test/architecture: 317/317.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MqfxcsDiEUZngybe9L72JQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant