-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add GetPosition method to DragStartingEventArgs, DragEventArgs, and DropEventArgs #16335
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments for code reuse, no need to obsolete a method if a default param value is used. vThe rest looks solid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// LGTM
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs
Outdated
Show resolved
Hide resolved
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nits that can be ignored, they are a matter of taste not of performance.
It wasn't doing anything
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs
Outdated
Show resolved
Hide resolved
@@ -200,7 +198,7 @@ void HandleDrop(object sender, Microsoft.UI.Xaml.DragEventArgs e) | |||
element = ve; | |||
} | |||
|
|||
var args = new DropEventArgs(datapackage?.View); | |||
var args = new DropEventArgs(datapackage?.View!, (relativeTo) => GetPosition(relativeTo, e)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the data package?.View
is null maybe we just exit early so we can avoid the null forgiveness operator?
Description of Change
Add
GetPosition(IElement relativeTo)
method to DragStartingEventArgs, DragEventArgs, and DropEventArgs. This method allows users to get the position of when the drag started and where it currently is relative to a specified element. If the specified element is null, then we get the position relative to the screen.This is similar to the behavior of TappedEventArgs.
All three platforms had native implementations for this functionality.
UI.Xaml.DragEventArgs
andUI.Xaml.DragStartingEventArgs
can get X and Y positionsMotionEvent
can natively get X and YLocationInView
from aIUIDragSession
There are also changes to the Controls.Sample app to show how drag and drop can send locations. The demos were recorded using the sample app.
Demos
Windows
Android
iOS
Screen.Recording.2023-08-16.at.4.40.26.PM.mov
Tests added
Added a 3 UI tests that ensure that the EventArgs are sending the correct location. These tests piggy back from the already existing test scaffolding for DragAndDrop. I cannot test to pixel perfect locations because it varies per platform, but I added a fair amount of checks as to where the relative location should be.
Issues Fixed
Fixes #2793
Remaining work