maui
maui copied to clipboard
Buttons with DragGestureRecogniser doesn't fire default Command on Android
Description
Hello, I wanted to implement a functionality where you can drag a button as well as single tap/click on it. It works in iOS and Mac Catalyst. However in Android, it only responds to drag event. The normal Command/TapGesture is not firing. Does anyone has a workaround for the same?
Steps to Reproduce
- Add a Button in Xaml.
<Button
Command="{Binding DefaultClickCommand}"
HorizontalOptions="Center"
Text="Button">
<Button.GestureRecognizers>
<DragGestureRecognizer DragStartingCommand="{Binding ButtonStartDragCommand}" />
</Button.GestureRecognizers>
</Button>
- Run the project on iOS. DefaultClickCommand and ButtonStartDragCommand working as expected.
- Run the project on Android. Only DragCommand is being fired. Button Click will not do anything.
Link to public reproduction project repository
No response
Version with bug
8.0.3
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 13
Did you find any workaround?
no workaround found.
Relevant log output
No response
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
the microsoft team doesn't believe that GestureRecognizers is problematic and doesn't work, even though on net 7 it is fine
It is bit different than your setup but will still leave it here.
If you have this hierarchy
Grid (or any layout) <-- here you have DragGestureRecognizer
Any UI element <-- here you have TapGestureRecognizer
Drag won't work .
If you move TapGestureRecognizer into the Grid on the same level DragGestureRecognizer is at it will work
In my case I had a list of items each item is a Grid with several columns each of which had its own TapGestureRecognizer. Attaching Drag to the Grid didn't work. To make it work I move the TapGestureRecognizer up (the one that has the most area covered because Drag will work only on those items that don't have TapGestureRecognizer if they are lower on the hierarchy). That way I can now drag starting on that biggest area and also taps on the icons lower on the hierarchy work but initiation of Drag starting on them doesn't work which isn't critical because the whole area outside of some small buttons are covered (the biggest area).
This is on MAUI 8.0.92.
Tried on both Android and iOS. On android works like I described above. On iOS the drag can be started from anywhere, even from those UI items that have TapGestureRecognizer and are lower on hierarhy. Taps on them also work fine.