Skip to content

Add PreviewView support to ContextMenu for LongPressed mode#806

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-document-preview-support
Draft

Add PreviewView support to ContextMenu for LongPressed mode#806
Copilot wants to merge 4 commits intomainfrom
copilot/add-document-preview-support

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

Adds a PreviewView property to ContextMenu so consumers can display a fully custom MAUI view as a preview on long-press — intended for cases like document lists where titles are truncated in the list row.

Description of Change

  • ContextMenu.PreviewView — new bindable View? property, only meaningful in LongPressed mode.

  • iOSContextMenuPreviewViewController wraps the MAUI view as a UIViewController and is returned from the UIContextMenuConfiguration previewProvider lambda, giving the native "peek" experience above the context menu.

  • AndroidContextMenuHandler shows the preview in a PopupWindow anchored above the element when the long-press triggers. The popup is wrapped in a FrameLayout with a MaterialShapeDrawable background (rounded corners, color_surface_default fill) and shadow elevation. The background is dimmed using FLAG_DIM_BEHIND with dimAmount = 0.5f to give a similar feel to the iOS peek experience. The popup is auto-dismissed via PopupMenu.IOnDismissListener.OnDismiss.

  • Sample added to ContextMenuSamples.xaml demonstrating a long document title + subtitle in the preview with two menu actions.

Usage:

<dui:ListItem dui:ContextMenuEffect.Mode="LongPressed">
    <dui:ContextMenuEffect.Menu>
        <dui:ContextMenu>
            <dui:ContextMenu.PreviewView>
                <dui:Label Text="Full document title that would otherwise be truncated" />
            </dui:ContextMenu.PreviewView>
            <dui:ContextMenuItem Title="Open" />
            <dui:ContextMenuItem Title="Delete" IsDestructive="True" />
        </dui:ContextMenu>
    </dui:ContextMenuEffect.Menu>
</dui:ListItem>

Todos

  • I have tested on an Android device.
  • I have tested on an iOS device.
  • I have supported accessibility

View original Slack conversation


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Add PreviewView bindable property to ContextMenu
- iOS: create ContextMenuPreviewViewController to wrap MAUI view as UIViewController preview
- iOS: use previewProvider in UIContextMenuConfiguration when PreviewView is set
- Android: show PreviewView in a PopupWindow above anchor on long press, dismiss with menu
- Add sample demonstrating PreviewView with a long document title use case
- Update CHANGELOG.md (minor bump to 55.3.0)

Co-authored-by: haavamoa <2527084+haavamoa@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for document preview in menu options Add PreviewView support to ContextMenu for LongPressed mode Mar 2, 2026
@haavamoa
Copy link
Member

haavamoa commented Mar 3, 2026

@copilot can you make sure the background gets dimmed / blurred on Android, and maybe add some shadow on the preview view? This will make it pop a bit more like it does on iOS.

…opup

- Wrap preview in FrameLayout with MaterialShapeDrawable (rounded corners,
  color_surface_default fill) and Elevation for shadow effect
- Apply FLAG_DIM_BEHIND with 0.5 dimAmount on the PopupWindow after showing
  so the background dims behind the preview popup

Co-authored-by: haavamoa <2527084+haavamoa@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot can you make sure the background gets dimmed / blurred on Android, and maybe add some shadow on the preview view? This will make it pop a bit more like it does on iOS.

Done in commit 1f1f110.

The ShowPreview() method on Android now:

  • Shadow: Wraps the preview in a FrameLayout with a MaterialShapeDrawable background (rounded size_2 corners, color_surface_default fill) and size_3 elevation — this gives the Material shadow that makes the card pop.
  • Dim: After ShowAsDropDown, grabs the popup's root window via WindowManager and sets FLAG_DIM_BEHIND with a dimAmount of 0.5f, darkening everything behind the preview card.

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.

2 participants