Repository navigation
context_menu: Lift an app-made preview beside the iOS system menu - #2297
Open
madcodelife wants to merge 3 commits into
Open
madcodelife wants to merge 3 commits into
madcodelife wants to merge 3 commits into
Conversation
ContextMenu gains a `preview` slot and an `onPreviewPress` event. On iOS, with `items`, the preview is made when a finger goes down on the trigger, laid out out of sight, and handed to UIContextMenuInteraction as the lifted preview; pressing it closes the menu and reports `onPreviewPress`.
madcodelife
marked this pull request as ready for review
November 17, 2026 16:35
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ContextMenuwithitemsshows the iOS system context menu (#2202), but the system always lifts the trigger itself. Apps often want to lift something else beside the menu: a conversation row that previews its last messages, a file row that previews the document, a link that previews the page. UIKit does this through the configuration's preview provider and commits a press on the preview throughwillPerformPreviewActionForMenuWithConfiguration.This adds both to
ContextMenu:system_menunow returns a zero-size view holding the component and the preview. The native component finds the trigger around that view and the preview beside it.preferredContentSizeset to its size. Until the preview is laid out (no window yet, zero size), the provider returns nil and the system lifts the trigger as before. A press on the preview commits with the dismiss style and is told aspreviewPressbeforeclose, the same way a chosen action is told before the dismissal.onPreviewPress(RustContextMenuEvents::PreviewPress,.on_preview_press(..)). The order matches a chosen item:onOpenChange(false, select),onPreviewPress,onClose.previewandonPreviewPressare not used, just likeitems. Withoutpreview, nothing changes on iOS either. No view is made, and the component getspreview: false, so the provider stays nil.A picture instead of a live view keeps the preview out of UIKit's view hierarchy: NSH keeps owning the view, and nothing moves between hosts while the system animates. The cost is that the preview does not update once the menu is up. That is fine for content previews, and the preview stays a plain NSH view the app styles as it wants.
Also:
website/elements/menu.md(English and zh-CN): "A preview in place of the trigger", the new prop and event.docs/dev/api-naming.md:preview/onPreviewPressnext toContextMenu's other NSH additions.Public API
nsh/baseContextMenu: proppreview?: JSX.Element(Rust.preview(..),Prop<Option<Slot>>). iOS only, withitems: what the system lifts beside its menu in place of the trigger. Not used on the other platforms.nsh/baseContextMenu: eventonPreviewPress(Rust.on_preview_press(|| ..),ContextMenuEvents::PreviewPress). iOS only: the preview was pressed, and the menu closed as for a chosen item.Test plan
cargo test -p nsh-base --test base -- menu::(57 passed), including three new tests:previewPress/close, with events in order;preview: falseand a touch makes nothing.cargo test -p nsh-engine --test engine context_menucargo clippy -p nsh-base --tests -- -D warnings, andnsh-platform-iosforaarch64-apple-ios-simcargo +nightly fmt --checkContextMenuhas apreview(a card made at touch-down) lifts the card beside the system menu instead of the row. The finger was a real touch fromnsh test --target ios.previewPresstests above, but not driven through UIKit (the test agent can't reach the system's preview window).