Skip to content
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

Merged
merged 47 commits into from
Aug 28, 2023

Conversation

jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented Jul 25, 2023

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.

  • Windows: UI.Xaml.DragEventArgs and UI.Xaml.DragStartingEventArgs can get X and Y positions
  • Android: MotionEvent can natively get X and Y
  • iOS/MacCatalyst: Can access LocationInView from a IUIDragSession

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

Win2

Android

Droid2

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

  • Write Tests
  • Determine whether DropEventArgs should also get a position

Copy link
Member

@mandel-macaque mandel-macaque left a 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.

src/Controls/src/Core/DragAndDrop/DragEventArgs.cs Outdated Show resolved Hide resolved
src/Controls/src/Core/DragAndDrop/DragEventArgs.cs Outdated Show resolved Hide resolved
src/Controls/src/Core/DragAndDrop/DragEventArgs.cs Outdated Show resolved Hide resolved
src/Controls/src/Core/DragAndDrop/DragStartingEventArgs.cs Outdated Show resolved Hide resolved
src/Controls/src/Core/DragAndDrop/DragStartingEventArgs.cs Outdated Show resolved Hide resolved
src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs Outdated Show resolved Hide resolved
davidbritch
davidbritch previously approved these changes Jul 28, 2023
Copy link
Contributor

@davidbritch davidbritch left a comment

Choose a reason for hiding this comment

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

/// LGTM

mandel-macaque
mandel-macaque previously approved these changes Jul 28, 2023
Copy link
Member

@mandel-macaque mandel-macaque left a 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.

@jknaudt21 jknaudt21 changed the title Add GetPosition method to DragStartingEventArgs and DragEventArgs Add GetPosition method to DragStartingEventArgs, DragEventArgs, and DropEventArgs Aug 17, 2023
@jknaudt21 jknaudt21 self-assigned this Aug 18, 2023
@@ -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));
Copy link
Member

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?

@PureWeen PureWeen enabled auto-merge (squash) August 28, 2023 18:15
@PureWeen PureWeen merged commit a3c248e into main Aug 28, 2023
38 checks passed
@PureWeen PureWeen deleted the fix-2793 branch August 28, 2023 19:28
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support to get drag and drop position from DragEventArgs
7 participants