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

[RC1] Implement Platform Args for Drag and Drop EventArgs #16962

Merged

Conversation

tj-devel709
Copy link
Member

@tj-devel709 tj-devel709 commented Aug 23, 2023

Description of Change

This PR exposes platform-specific properties from Drag and Drop Maui Gestures to our customers allowing more customization of Drag and Drop interactions. There are five different events related to drag and drop gestures that use four different EventArg classes that will now contain the following classes:

PlatformDragStartingEventArgs

iOS / Catalyst

UIKit.UIView? Sender { get; }
UIKit.UIDragInteraction DragInteraction { get; }
UIKit.IUIDragSession DragSession { get; }
SetItemProvider (Foundation.NSItemProvider itemProvider)
SetPreviewProvider(Func<UIKit.UIDragPreview?> previewProvider)
SetDragItems(UIDragItem[] dragItems)

Android

Android.Views.View Sender { get; }
Android.Views.MotionEvent MotionEvent { get; }
SetDragShadowBuilder(Android.Views.View.DragShadowBuilder dragShadowBuilder)
SetClipData(Android.Content.ClipData clipData)

Windows

Microsoft.UI.Xaml.UIElement Sender { get; }
Microsoft.UI.Xaml.DragStartingEventArgs DragStartingEventArgs { get; }
bool Handled { get; set; }

PlatformDropCompletedEventArgs

iOS / Catalyst

UIKit.UIView? Sender { get; }
UIKit.UIDragInteraction? DragInteraction { get; }
UIKit.IUIDragSession? DragSession { get; }
UIKit.UIDropOperation? DropOperation { get; }
UIKit.UIDropInteraction? DropInteraction { get; }
UIKit.IUIDropSession? DropSession { get; }

Android

Android.Views.View Sender { get; }
Android.Views.DragEvent DragEvent { get; }

Windows

Microsoft.UI.Xaml.UIElement Sender { get; }
Microsoft.UI.Xaml.DropCompletedEventArgs DropCompletedEventArgs { get; }

PlatformDropEventArgs

iOS / Catalyst

UIKit.UIView? Sender { get; }
UIKit.UIDropInteraction? DropInteraction { get; }
UIKit.IUIDropSession? DropSession { get; }

Android

Android.Views.View Sender { get; }
Android.Views.DragEvent DragEvent { get; }

Windows

object Sender { get; }
Microsoft.UI.Xaml.DragEventArgs DragEventArgs { get; }

PlatformDragEventArgs

iOS / Catalyst

UIKit.UIView? Sender { get; }
UIKit.UIDropInteraction? DropInteraction { get; }
UIKit.IUIDropSession? DropSession { get; }
SetDropProposal(UIKit.UIDropProposal dropProposal)

Android

Android.Views.View Sender { get; }
Android.Views.DragEvent DragEvent { get; }

Windows

object Sender { get; }
Microsoft.UI.Xaml.DragEventArgs DragEventArgs { get; }
bool Handled { get; set;}

Sample

Showing overwriting the drag Shadow on iOS

image

UITest added

DragNDropiOSUITestDemo.mov

Issues Fixed

Fixes #16992

@tj-devel709 tj-devel709 marked this pull request as ready for review August 24, 2023 21:04
@tj-devel709 tj-devel709 requested a review from a team as a code owner August 24, 2023 21:04
@PureWeen PureWeen requested review from PureWeen, mikeparker104 and mattleibow and removed request for StephaneDelcroix August 24, 2023 21:09
@samhouts samhouts added this to the .NET 8 GA milestone Aug 28, 2023
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

Quite a few changes here, so I just wanted to drop a review so that I don't go down a path that was already discussed. My main issues are:

  • the apparent "not super required" platform args in the ctors of the event args. Should we add those to banned apis so we don't use it
  • the total change of the way Handled is now working. This is potentially more breaking and also I am thinking it is still useful on other platforms... maybe?

/// <summary>
/// Gets the native view attached to the event.
/// </summary>
public object Sender { get; }
Copy link
Member

Choose a reason for hiding this comment

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

Should this be Microsoft.UI.Xaml.UIElement?

Copy link
Member Author

Choose a reason for hiding this comment

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

Some of the calling methods used just have their sender type as object as such:

void HandleDrop(object sender, Microsoft.UI.Xaml.DragEventArgs e)
{ ... }

Copy link
Member Author

Choose a reason for hiding this comment

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

I could type cast and check for Microsoft.UI.Xaml.UIElement, but I was not sure if we expect that every time or if there was a reason for the 'object'

Copy link
Member

Choose a reason for hiding this comment

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

Sender should be the object you are attaching to, so if they are all UIElement, maybe we can keep it consistent

Copy link
Member

Choose a reason for hiding this comment

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

Same as above, this probably should be UIElement - even though it is object. The events are only available on UIElement so should never be anything other than element.

@PureWeen PureWeen requested a review from mattleibow August 29, 2023 15:15
@tj-devel709 tj-devel709 enabled auto-merge (squash) August 30, 2023 04:26
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

A few last comments, but looking good. It is more defensive decision making for the func... Not sure if it will cause issues with memory leaks or something. Should be fine, but we can always add an API in RC2 but we can't really take away.

/// <summary>
/// Gets the native view attached to the event.
/// </summary>
public object Sender { get; }
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, this probably should be UIElement - even though it is object. The events are only available on UIElement so should never be anything other than element.

mattleibow
mattleibow previously approved these changes Aug 30, 2023
Copy link
Member

@dalexsoto dalexsoto left a comment

Choose a reason for hiding this comment

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

❤️

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Platform-specific properties for Drag and Drop Gesture Recognizer EventArgs
4 participants