-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[RC1] Implement Platform Args for Drag and Drop EventArgs #16962
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
Merged
tj-devel709
merged 29 commits into
dotnet:main
from
tj-devel709:GestureRecognizer-DragNDrop-Extensions-Final
Aug 30, 2023
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
a6d34e1
Introduce the Platform Args for Drag and Drop Event Args
tj-devel709 6bfa640
First pass of review - remove handled and others
tj-devel709 fd08b8a
change prop names
tj-devel709 2b1cf5c
windows uitest changes
1faffc8
UITest does not drag and release at starting position
tj-devel709 58a1959
APIPublic docs
tj-devel709 1fb38b0
Merge branch 'main' into GestureRecognizer-DragNDrop-Extensions-Final
tj-devel709 9bc61ce
null reference for ui tests
tj-devel709 9173081
Merge remote-tracking branch 'TJ/GestureRecognizer-DragNDrop-Extensio…
tj-devel709 c0b84fc
fix windows public api txt
tj-devel709 bc05e0d
Suppress error in compat that is not being used
tj-devel709 4d841a6
Merge branch 'main' into GestureRecognizer-DragNDrop-Extensions-Final
tj-devel709 8b302f4
Set PlatformArgs in constructors
tj-devel709 2a6d88d
Add additional docs and throw exception if localObject is set
tj-devel709 4209d8f
Fix merge conflicts
tj-devel709 d4ea01c
Make the constructors with PlatformArgs public
tj-devel709 b59d400
Add the eventargs.Handled property back in and small syntax changes
tj-devel709 795f86b
various small changes
tj-devel709 b514eab
Merge branch 'main' into GestureRecognizer-DragNDrop-Extensions-Final
tj-devel709 60c4b64
Windows null dereference fix
tj-devel709 93ff03b
Merge remote-tracking branch 'TJ/GestureRecognizer-DragNDrop-Extensio…
tj-devel709 779b484
A few different discussed changes
tj-devel709 bea4365
Merge conflict - missing bracket in test
tj-devel709 22c52f0
Nullable datapackage in constructor
tj-devel709 8dd3ca4
Make the public ctors internal and cast the winUI UIElement
tj-devel709 dd8cfc2
change type in public api
29afeff
Merge branch 'main' into GestureRecognizer-DragNDrop-Extensions-Final
tj-devel709 7d5c5c4
Merge branch 'main' into pr/16962
mattleibow 82c9ad6
Fix the PublicAPI
mattleibow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Controls/samples/Controls.Sample.UITests/Elements/DragAndDropEventArgs.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| AutomationId="DragAndDropEventArgs" | ||
| x:Class="Maui.Controls.Sample.DragAndDropEventArgs"> | ||
| <StackLayout> | ||
| <StackLayout Orientation="Horizontal"> | ||
| <Label HeightRequest="200" WidthRequest="200" AutomationId="LabelDragElement" | ||
| Text="Drag me Over the Purple Box, off the purple box, drop me on the purple box, and then verify all the correct events fired"> | ||
| <Label.GestureRecognizers> | ||
| <DragGestureRecognizer DragStarting="DragStarting" DropCompleted="DropCompleted"></DragGestureRecognizer> | ||
| </Label.GestureRecognizers> | ||
| </Label> | ||
| <Label HeightRequest="200" HorizontalOptions="FillAndExpand" Background="Purple" AutomationId="DragTarget"> | ||
| <Label.GestureRecognizers> | ||
| <DropGestureRecognizer DragLeave="DragLeave" DragOver="DragOver" Drop="Drop"></DropGestureRecognizer> | ||
| </Label.GestureRecognizers> | ||
| </Label> | ||
| </StackLayout> | ||
| <Label x:Name="events" AutomationId="DragEventsLabel" Text="EventsLabel"> | ||
| <Label.GestureRecognizers> | ||
| <DropGestureRecognizer></DropGestureRecognizer> | ||
| </Label.GestureRecognizers> | ||
| </Label> | ||
| </StackLayout> | ||
| </ContentView> |
151 changes: 151 additions & 0 deletions
151
src/Controls/samples/Controls.Sample.UITests/Elements/DragAndDropEventArgs.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| using Microsoft.Maui.Controls; | ||
| using Microsoft.Maui.Controls.Xaml; | ||
|
|
||
| namespace Maui.Controls.Sample; | ||
|
|
||
| [XamlCompilation(XamlCompilationOptions.Compile)] | ||
| public partial class DragAndDropEventArgs : ContentView | ||
| { | ||
| bool _emittedDragOver = false; | ||
| public DragAndDropEventArgs() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
|
|
||
| void AddEvent(string name) | ||
| { | ||
| events.Text += $"{name},"; | ||
| } | ||
|
|
||
| void DragStarting(object sender, DragStartingEventArgs e) | ||
| { | ||
| _emittedDragOver = false; | ||
| if (e.PlatformArgs is PlatformDragStartingEventArgs platformArgs) | ||
| { | ||
| #if IOS || MACCATALYST | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DragStarting:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DragInteraction is not null) | ||
| AddEvent("DragStarting:" + nameof(platformArgs.DragInteraction)); | ||
| if (platformArgs.DragSession is not null) | ||
| AddEvent("DragStarting:" + nameof(platformArgs.DragSession)); | ||
| #elif ANDROID | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DragStarting:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.MotionEvent is not null) | ||
| AddEvent("DragStarting:" + nameof(platformArgs.MotionEvent)); | ||
| #elif WINDOWS | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DragStarting:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DragStartingEventArgs is not null) | ||
| AddEvent("DragStarting:" + nameof(platformArgs.DragStartingEventArgs)); | ||
| AddEvent("DragStarting:" + nameof(platformArgs.Handled)); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| void DropCompleted(object sender, DropCompletedEventArgs e) | ||
| { | ||
| if (e.PlatformArgs is PlatformDropCompletedEventArgs platformArgs) | ||
| { | ||
| #if IOS || MACCATALYST | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DropCompleted:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DropInteraction is not null) | ||
| AddEvent("DropCompleted:" + nameof(platformArgs.DropInteraction)); | ||
| if (platformArgs.DropSession is not null) | ||
| AddEvent("DropCompleted:" + nameof(platformArgs.DropSession)); | ||
| #elif ANDROID | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DropCompleted:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DragEvent is not null) | ||
| AddEvent("DropCompleted:" + nameof(platformArgs.DragEvent)); | ||
| #elif WINDOWS | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DropCompleted:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DropCompletedEventArgs is not null) | ||
| AddEvent("DropCompleted:" + nameof(platformArgs.DropCompletedEventArgs)); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| void DragLeave(object sender, DragEventArgs e) | ||
| { | ||
| if (e.PlatformArgs is PlatformDragEventArgs platformArgs) | ||
| { | ||
| #if IOS || MACCATALYST | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DragLeave:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DropInteraction is not null) | ||
| AddEvent("DragLeave:" + nameof(platformArgs.DropInteraction)); | ||
| if (platformArgs.DropSession is not null) | ||
| AddEvent("DragLeave:" + nameof(platformArgs.DropSession)); | ||
| #elif ANDROID | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DragLeave:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DragEvent is not null) | ||
| AddEvent("DragLeave:" + nameof(platformArgs.DragEvent)); | ||
| #elif WINDOWS | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DragLeave:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DragEventArgs is not null) | ||
| AddEvent("DragLeave:" + nameof(platformArgs.DragEventArgs)); | ||
| AddEvent("DragLeave:" + nameof(platformArgs.Handled)); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| void DragOver(object sender, DragEventArgs e) | ||
| { | ||
| if (!_emittedDragOver) // This can generate a lot of noise, only add it once | ||
| { | ||
| if (e.PlatformArgs is PlatformDragEventArgs platformArgs) | ||
| { | ||
| #if IOS || MACCATALYST | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DragOver:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DropInteraction is not null) | ||
| AddEvent("DragOver:" + nameof(platformArgs.DropInteraction)); | ||
| if (platformArgs.DropSession is not null) | ||
| AddEvent("DragOver:" + nameof(platformArgs.DropSession)); | ||
| #elif ANDROID | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DragOver:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DragEvent is not null) | ||
| AddEvent("DragOver:" + nameof(platformArgs.DragEvent)); | ||
| #elif WINDOWS | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("DragOver:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DragEventArgs is not null) | ||
| AddEvent("DragOver:" + nameof(platformArgs.DragEventArgs)); | ||
| #endif | ||
| } | ||
| _emittedDragOver = true; | ||
| } | ||
| } | ||
|
|
||
| void Drop(object sender, DropEventArgs e) | ||
| { | ||
| if (e.PlatformArgs is PlatformDropEventArgs platformArgs) | ||
| { | ||
| #if IOS || MACCATALYST | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("Drop:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DropInteraction is not null) | ||
| AddEvent("Drop:" + nameof(platformArgs.DropInteraction)); | ||
| if (platformArgs.DropSession is not null) | ||
| AddEvent("Drop:" + nameof(platformArgs.DropSession)); | ||
| #elif ANDROID | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("Drop:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DragEvent is not null) | ||
| AddEvent("Drop:" + nameof(platformArgs.DragEvent)); | ||
| #elif WINDOWS | ||
| if (platformArgs.Sender is not null) | ||
| AddEvent("Drop:" + nameof(platformArgs.Sender)); | ||
| if (platformArgs.DragEventArgs is not null) | ||
| AddEvent("Drop:" + nameof(platformArgs.DragEventArgs)); | ||
| #endif | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| #nullable disable | ||
| using System; | ||
|
|
||
| namespace Microsoft.Maui.Controls | ||
|
|
@@ -7,5 +6,26 @@ namespace Microsoft.Maui.Controls | |
| public class DropCompletedEventArgs : EventArgs | ||
| { | ||
| DataPackageOperation DropResult { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="DropCompletedEventArgs"/> class. | ||
| /// </summary> | ||
| public DropCompletedEventArgs() | ||
| { | ||
| } | ||
|
Comment on lines
+13
to
+15
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add all the non-platform args ctors to the banned apis? Then we don't accidentally use the wrong one? |
||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="DropCompletedEventArgs"/> class. | ||
| /// </summary> | ||
| /// <param name="platformArgs">The platform-specific data associated with the drag.</param> | ||
| internal DropCompletedEventArgs(PlatformDropCompletedEventArgs platformArgs) : this() | ||
| { | ||
| PlatformArgs = platformArgs; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the platform-specific arguments associated with the <see cref="DropCompletedEventArgs"/>. | ||
| /// </summary> | ||
| public PlatformDropCompletedEventArgs? PlatformArgs { get; } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.