Open jonmdev opened 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!
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Hi, have you seen the API Microsoft.UI.Xaml.Media.VisualTreeHelper.FindElementsInHostCoordinates? It might help you here. Thanks!
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
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.
Thanks for the response, it makes sense. We'll leave this open and consider it in the future. Thanks!
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:
touchView.Touch += FunctionToRunOnTouch
MotionEvent
.e.Handled = true;
if done with it.MotionEvent clonedEvent = MotionEvent.Obtain(e.Event)
pickedView.DispatchTouchEvent(clonedEvent)
2) In iOS .NET:
public override UIView HitTest(CGPoint point, UIEvent uievent)
which returns the UIView that should receive the click.base.HitTest()
within this invokes the default behavior.TouchesBegan
,TouchesCancelled
,TouchesMoved
&TouchesEnded
which then lets us track the touch data for each touch as an array ofUITouch
objects on each update.3) In WinUI3:
Scope