AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.96k stars 2.25k forks source link

Drag+Drop doesn't work with touch and pen devices on Windows #9138

Open anewton opened 2 years ago

anewton commented 2 years ago

Describe the bug Drag+Drop no longer working as expected on desktop platforms for pointer devices other than mouse, after updating to Avalonia version 11.0.0-preview2. Drag+Drop for Windows Desktop no longer works for Pen and Touch since EnableMultitouch was removed. Can no longer set EnableMultitouch to false, which allowed Pen and Touch drag+drop to work. Note: Mousepad or Mouse drag+drop still works as expected.

To Reproduce

  1. Clone the Avalonia repository on Windows from the doumented instructions: Build instructions
  2. Publish the ControlCatalog.NetCore using the following cli commands:
    # from root Avalonia source folder
    cd ./Samples/ControlCatalog.NetCore
    dotnet publish -c Release -p:PublishSingleFile=true -p:PublishTrimmed=true -p:IncludeNativeLibrariesForSelfExtract=true -p:CopyOutputSymbolsToPublishDirectory=false -r win-x64 --self-contained=true
  3. Copy the publish folder to a Windows 10 or newer touch enabled laptop or tablet. The publish folder will be located in the following path: ./Avalonia/Samples/ControlCatalog.NetCore/bin/Release/net6.0/win-x64/publish
  4. From the Windows touch enable laptop or tablet, run the sample application and navigate to the Drag+Drop sample page.
  5. Drag and drop the custom item to the far right destination square using each of the following 3 devices:
    • Mouse
    • Mousepad (trackpad)
    • Touch (single finger as device)
    • Pen
  6. Note that only the Mouse or Mousepad as pointer devices will work.

Expected behavior All touch devices should allow the drag and drop feature to work on desktop touch screens. In version 0.10.18 of Avalonia, the flag EnableMultitouch could be set to false and touch for all pointer types on desktop operating systems did work. Please refer to this Gitter thread which led me to set the flag false in the first place. https://gitter.im/AvaloniaUI/Avalonia?at=620f73fd708e9c3dd7857a9c

Screenshots image

Desktop (please complete the following information):

Additional context Also noticed that MacOs trackpad drag+drop stopped working. I have uploaded two sample projects to my repo to demonstrate the issue between two Avalonia versions. That code can be found here (as of this writing): Avalonia.DragDrop issue code.

anewton commented 1 year ago

Quick update: Hoping to see this magically fixed in a future version or from another bug report. In the meantime, wanted to mention that I found a decent workaround. My workaround does not support pen on a Windows 11 tablet for drag/drop. But does work for touch and mouse trackpad/mouse. Subclassed a user control with a custom Panel class that starts drag with OnPointerPressed, OnPointerMoved, OnPointerRelease, OnPointerCaptureLost. In OnPointerReleased, my code calls DragDrop.DoDragDrop. Based on the Avalonia sample PointerCanvas.cs and trial and error. Subclassed an ItemsControl too. Set AllowDrop to true and implemented a DragDrop.DropEvent handler method for the Drop. I'd prefer to see the sample code working again for Drag and Drop using pen, touch, and mouse. But for now my workaround works for my use cases. Please keep this bug open unless it is tracked elsewhere. Thanks!

anewton commented 1 year ago

Cleaned up my sample application to prevent cascade of mouse events from duplicated Popup child control that was being created. Now creating a bitmap from the control being dragged to display as the Popup's child.

Brought in sample controls from Avalonia to help with testing on a tablet. Added these fixes only to the "ReleaseVersion" project.

Upgraded Avalonia from v11.0.2 to v.11.0.4.

Still seeing the same issue for my custom Drag/Drop control. Sample Avalonia Drag Drop page was still showing the reported issue above. Not sure what is causing the pen or touch pointer to break the drag/drop.

anewton commented 1 year ago

@maxkatz6 FYI, I've been making changes to my referenced test projects. Found that a custom GestureRecognizer worked well for Touch DnD but still not quite there for the Pen (stylus). At this point, it seems like some UI thread blocking or perhaps a GestureRecognizer is preventing the DragDrop.DoDragDrop method from working for a Pen input.

tovgroliv commented 9 months ago

Same behavior on Android

ztl8702 commented 9 months ago

It seems that DragDrop.DoDragDrop also hangs on iOS. AvaloniaVersion 11.0.6

jp2masa commented 9 months ago

I think drag and drop is not supported on iOS. However, that hang may have been fixed by #13942, so you should upgrade at least to v11.0.7.

anewton commented 9 months ago

Hi @tovgroliv , @ztl8702 , and @jp2masa

I wrote a sample app for Windows desktop that might be easy to port to iOS and Android. I have not tried iOS for anything yet. You might take a look at this. The idea that I stumbled on was that it seemed a GestureRecognizer may have taken over pointer input. So I wrote a very simple custom gesture recognizer. That can be found here: https://github.com/anewton/Avalonia.Testing/blob/ca43c21d2836246699b306ae30051e0e55e382ee/Avalonia.DragDrop/ReleaseVersion/ReleaseVersion/Controls/DragGestureRecognizer.cs

If anyone can try that out in a sample app on iOS and Android, it might make a bug report more interesting for the Avalonia team.

Thanks!