Skip to content

[Catalyst] WebView does not display ContextFlyout on right-click - fix #30309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Jun 30, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

Note: This approach adds a transparent mask view over the WKWebView to intercept right-click events and display the MAUI ContextFlyout. As a result, this intentionally blocks the default WKWebView context menus on right-click.

Issues Fixed

Fixes #30308

The demo can be found here

<WebView x:Name="ContextMenuWebView" Source="https://bing.com" MinimumHeightRequest="400">
    <FlyoutBase.ContextFlyout>
        <MenuFlyout>
            <MenuFlyoutItem Text="Go to MAUI repo" Clicked="OnWebViewGoToSiteClicked"></MenuFlyoutItem>
            <MenuFlyoutSeparator />
            <MenuFlyoutItem Text="Invoke some JS" Clicked="OnWebViewInvokeJSClicked"></MenuFlyoutItem>
        </MenuFlyout>
    </FlyoutBase.ContextFlyout>
</WebView>
Before After
Screen.Recording.2025-06-30.at.01.59.28.mov
Screen.Recording.2025-06-30.at.01.58.12.mov

@Copilot Copilot AI review requested due to automatic review settings June 30, 2025 00:06
@kubaflo kubaflo requested a review from a team as a code owner June 30, 2025 00:06
@kubaflo kubaflo requested review from rmarinho and jsuarezruiz June 30, 2025 00:06
@kubaflo kubaflo self-assigned this Jun 30, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a context menu display issue on Catalyst by ensuring right-click events on a WKWebView are intercepted appropriately.

  • Adds a mask view to WKWebView to intercept right-clicks and pass them to the context menu interaction.
  • Defines a custom InterceptRightClickWebViewMaskView class with an overridden HitTest to handle secondary (right-click) events.

// If the view is a WKWebView, we need to intercept right-clicks
// to show the context menu, so we add a mask view that intercepts
// right-clicks and passes them to the context menu interaction.
var maskView = new InterceptRightClickWebViewMaskView(uiView.Bounds)
Copy link
Preview

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mask view created for WKWebView is never removed when the context flyout is cleared. Consider adding logic to remove the mask view to prevent potential memory leaks or interference with later interactions.

Copilot uses AI. Check for mistakes.

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jun 30, 2025
@kubaflo kubaflo added platform/macos macOS / Mac Catalyst area-controls-contextmenu ContextMenu labels Jun 30, 2025
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you include a test? On UITest can use a method to always right click in a specific coordinates.

Copy link
Member

@jfversluis jfversluis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See Javiers comment!

@jfversluis jfversluis added the s/pr-needs-author-input PR needs an update from the author label Jul 2, 2025
Copy link
Contributor

Hi @@kubaflo. We have added the "s/pr-needs-author-input" label to this issue, which indicates that we have an open question/action for you before we can take further action. This PRwill be closed automatically in 14 days if we do not hear back from you by then - please feel free to re-open it if you come back to this PR after that time.

@kubaflo kubaflo removed the s/pr-needs-author-input PR needs an update from the author label Jul 2, 2025
@kubaflo
Copy link
Contributor Author

kubaflo commented Jul 2, 2025

Done

@kubaflo
Copy link
Contributor Author

kubaflo commented Jul 2, 2025

Let me know if we want to proceed with this pr :) If so then I will include a test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-contextmenu ContextMenu community ✨ Community Contribution platform/macos macOS / Mac Catalyst
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Catalyst] WebView does not display ContextFlyout on right-click
3 participants