microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.38k stars 683 forks source link

Proposal: Add Method to Hit Test and Manually Transfer Clicks (like in Android & iOS) #9667

Open jonmdev opened 6 months ago

jonmdev commented 6 months ago

Proposal: Add Method to Hit Test and Manually Transfer Clicks (like in Android & iOS)

Summary

Currently there is no way in WinUI C# to hit test a click and then decide what to do based on the hit test (eg. let the platform activate the given clicked element, transfer the click to another element, or run some other function).

In Android .NET and iOS .NET there are working methods for this, but no such methods exist in WinUI3. Adding proper methods will allow more unified coding experiences with .NET MAUI and general modern designs. It will bring WinUI3 up to standard with the other OS's.

Rationale

.NET MAUI is supposed to represent a unified platform for development for Android, iOS, and WinUI3. Yet this major function is missing from WinUI3 disallowing us to build unified experiences where clicks can be custom managed across platforms.

WinUI3 should be brought up to spec with Android & iOS so it has a comparable feature set for custom and more advanced management of user click events. This will allow, for example, management of custom nested carousels or the creation of overlapping clickable objects with complex rules.

To illustrate:

1) In Android .NET:

2) In iOS .NET:

3) In WinUI3:

Scope

Capability Priority
This proposal will allow developers to Hit Test clicks from an overlay view Must
This proposal will allow developers to read the status of all active clicks on each update from the overlay view Must
This proposal will allow developers to manually control what UI Elements are activated or assigned to the clicks Must
github-actions[bot] commented 6 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Open similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

JesseCol commented 4 months ago

Hi, have you seen the API Microsoft.UI.Xaml.Media.VisualTreeHelper.FindElementsInHostCoordinates? It might help you here. Thanks!

jonmdev commented 4 months ago

Microsoft.UI.Xaml.Media.VisualTreeHelper.FindElementsInHostCoordinates

Thank you, that is interesting. I wasn't aware of that. Maui actually has a built in cross-platform function like this as well:

VisualTreeElementExtensions.GetVisualTreeElements

https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.visualtreeelementextensions.getvisualtreeelements?view=net-maui-8.0

And one can deconstruct and alter the code easily enough that it uses in each platform.

The problem is not being able to find what is at a given coordinate, but rather deciding whether or not the component (or another over/under or simultaneous peripherally) should receive the click or be activated by it.

We have no way to control this in Windows.

We cannot DispatchTouchEvent like in Android from a click catching layer at will. Nor can we monitor all the active touch data on every update like in Android to decide what to do with it.

Nor can we return a custom element vs. decide to invoke base.HitTest() to invoke the default click behavior as in iOS. Or use the click data from the layer that caught it to do other tasks at will as in iOS.

That is where the WinUI3 deficit is.

If I am managing my own nested carousels made from basic Maui Layout/Image elements for example with 2D click and drag functions, I can determine in iOS and Android if the click is made in this region, and manipulate the elements myself based on this and the click data.

Or if I want a click to go straight through to a native text editor field, I can allow this and not interfere.

Such management is not possible in WinUI3, because we have no access to the ongoing touches/clicks and cannot pass through clicks selectively to the native element management.

All of those things are possible in Android and iOS for what I think are very good reasons.

Hopefully that makes sense. Please let me know if not. Thanks.

JesseCol commented 4 months ago

Thanks for the response, it makes sense. We'll leave this open and consider it in the future. Thanks!