Skip to content

Show a picture and a tick in menu rows - #224

Draft
simonhamp wants to merge 1 commit into
mainfrom
feat/menu-item-images
Draft

simonhamp wants to merge 1 commit into
mainfrom
feat/menu-item-images

Conversation

@simonhamp

Copy link
Copy Markdown
Member

Menu rows (:menu, :context-menu, :trailing-menu) can now show a picture in place of their icon, and a tick.

  • image: a remote URL, a device path or a public/ path, as for <native:image>. Core's NavAction::image() already sends it.
  • image_shape: circle (default) or rounded, a square with rounded corners.
  • checked: a tick on the option the menu has picked.

The icon shows while the picture loads and stays if it fails, so rows should keep one. image_shape and checked aren't on NavAction yet, so for now they go on the element:

NavAction::make('me')->label('Simon')->icon(...)->image($avatar)
    ->toElement()
    ->setProp('checked', true)

A ->checked() and ->imageShape() on NavAction in core would be the nicer API later.

iOS. A SwiftUI Menu is a UIMenu underneath. It draws a snapshot of each row's image and can't load or clip one. So NativeUIMenuImages fetches the pictures as soon as the pressable, button or list row that opens the menu is on screen, cuts them to shape at 24pt and hands the rows ready-made images. They're kept in memory for the life of the app. A checked row is a Toggle, so iOS draws its own tick in its own place. The three copies of the row renderer (pressable, button, list item) are now one, NativeUIMenuItem.

Android. renderAttachedMenuItem (shared by all three already) loads the picture with Coil, clipped to shape, and puts a primary-coloured tick at the end of a checked row. TalkBack hears the checked row as selected.

What to check: a menu opened before its pictures have arrived shows icons; reopening it shows the pictures. I haven't seen a picture arrive while the menu was open on iOS.

Tests: 531 passed (new MenuItemImageTest, and IosPressableMenuItemsTest follows the moved row renderer).

Screenshots

From the devnull app's Post as menu (NativePHP/dev-null-app, branch feat/post-as-avatars), iPhone 18 Pro on iOS 27.0 and an API 35 emulator, against a local server.

iOS light iOS dark Android light Android dark
Before
After

🤖 Generated with Claude Code

A :menu, :context-menu or :trailing-menu row can now carry an image
(an account's avatar, say) in place of its icon, cut to a circle or,
with image_shape "rounded", a rounded square. The icon shows while the
picture loads and stays if it fails. A row with checked has a tick, for
the option a menu has picked.

Core's NavAction already sends image. image_shape and checked go on the
element with setProp:

    NavAction::make('me')->label('Simon')->icon(...)->image($avatar)
        ->toElement()->setProp('checked', true)

iOS: a SwiftUI Menu is a UIMenu underneath, which can't load or clip an
image itself. NativeUIMenuImages fetches the pictures as soon as the
pressable, button or row that opens the menu is on screen, cuts them to
shape at 24pt and hands the rows ready-made images. A checked row is a
Toggle, so iOS draws its own tick. The three copies of the row renderer
(pressable, button, list item) are now one, NativeUIMenuItem.

Android: renderAttachedMenuItem loads the picture with Coil, clipped to
shape, and puts a tick at the end of a checked row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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