maui
maui copied to clipboard
SwipeGestureRecognizer is not working
Description
SwipeGestureRecognizer is not working on Android, the Swiped event is never raised. I only found this issue #14 which says its in Pending state but the issue hasn't been updated since 2 years. The documentation for MAUI sounds like it's implemented.
Is this a bug or is it really not implemented yet?
Steps to Reproduce
<Button>
<Button.GestureRecognizers>
<SwipeGestureRecognizer Direction="Right" Swiped="SwipeGestureRecognizer_Swiped"/>
</Button.GestureRecognizers>
</Button>
SwipeGestureRecognizer_Swiped event is never raised when I swipe in Android Simulator.
Version with bug
Release Candidate 3 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 12, API 31, Android Simulator
Did you find any workaround?
No response
Relevant log output
No response
Does it work if you use it on another element? Preferably one that does not have its own response to input? A Label maybe?
Thanks for asking. It also does NOT work on a Label:
https://user-images.githubusercontent.com/14368203/169767229-cff1d53a-3515-4afd-aba7-bf925786010f.mp4
not repro with vs main build(32523.339.main).
Can you repro this with RC3? I am not able to test main build but with RC3 so question is if its just RC3 vs main or if its just you aren't able to reproduce at all.
Here is my project, would you like to verify it on Android emulator? Just swipe the button and the counter is expected to increase. MauiApp7403.zip
RC3, API 31, Android 12, Pixel 5 => NOT working. Assuming you tested it on Android 12 API 31 as well, then you or someone else need to test it on RC3 to make sure this is definitely fixed. But I doubt this is "suddenly" fixed in main branch because I cannot find any issue about that. So even if main branch goes live it probably wouldn't work on my end as well.
https://user-images.githubusercontent.com/14368203/169996780-5b8d2980-9589-487c-8a15-3e813e314b69.mp4
.
It is definitely implemented (GestureManager class). Testing on the current amin branch seems to work fine.

Could you try with GA?
Hi @Symbai. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
I dont know how to try the main branch. Is there an installer? I'm not good at cloning and building and running such large projects. Like I said I'm using RC3 via VS installer. I believe its easier for you to run it on that, then having me trying to get the main branch working.
If it doesn't work for you on RC3 as well but it works in main, then we can close the issue. But if it also works for you in RC3, then its just broken on my end and we need to figure out why.
@jsuarezruiz I've now downloaded the MAIN branch following this guide. And it still does not work. No idea why it does for you, are you using the same Android version and device?
I confirm it works on GA with Label, but doesn't work on custom controls
What are "custom controls"? I've tested this on a Button and a Listview and on both it fails.
@VincentBu can you test gain please?
@PureWeen verified with vs main build 32630.352, SwipeGestureRecognizer works fine.
No idea what I am doing wrong then. Does not work in Android Emulator and on physical devices. I had 12 people testing it on their physical devices and all confirmed SwipeGesture isn't working. Can this depend on what machine you are building / publishing the project?
Verified on 6.0.400 and it doesn't work. To check use this sample: https://github.com/VladislavAntonyuk/MauiSamples/blob/main/CardLayout/CardsLayout.cs#L86 Replace PanGestureRecognizer with SwipeGestureRecognizer. PanGestureRecognizer fires events but SwipeGestureRecognizer doesn't.
I can confirm what @VladislavAntonyuk said. PanGestureRecognizer is also working for me (as soon as I click, hold and drag the mouse in the emulator, the event is raised), but SwipeGestureRecognizer does not. I click, hold and drag, nothing happens and the Swiped event is never raised.
These were the changes I made:
public CardsLayout()
{
var panGesture = new SwipeGestureRecognizer();
panGesture.Swiped += PanGesture_Swiped;
GestureRecognizers.Add(panGesture);
}
private void PanGesture_Swiped(object? sender, SwipedEventArgs e)
{
throw new NotImplementedException(); // <-- never raised
}
repro with VladislavAntonyuk's sample.
I confirm this issue still exists in .NET MAUI 7. I added swipe gesture to a content view. In Android, the gesture never works!!
In the grid the error its the same , i think in all controls
Today I tested Gesture Detector Handlers on Android, and custom control extending ContentView. Everything worked (Pan, Pinch, Tap) except Swipe. Maui 7.0. This is important feature, not only for custom controls.
I am working on a sample app that I Should have out later today. It will demonstrate how to use swipe in a maui app with mvvm, using community toolkit. I am writing it now. I have it working in an app. I just want to write it all out so people can see it working with all the various layouts, buttons, images, etc. I will have examples in sample app for everyone to look at. It works out the methods microsoft put up on help pages included features not implemented yet. Using mvvm and toolkit I have figured out how to make it work.
Edit: Ok I have working solution using Maui with most layouts tested. It works in windows, android emulator, and android hardware devices. I can't test on Mac or iOS as I don't have a developer account yet. I also do not have a mac. So no direct hardware testing on Mac. After I get a Apple developer Account I can test on my Ipad.
Here is link to repo you can look it with samples that I made earlier today. https://github.com/ne0rrmatrix/SwipeGesturesSample.git
https://github.com/ne0rrmatrix/SwipeGesturesSample.git
The repro link seems not to be working, could you update it?
@jsuarezruiz please try my sample: https://github.com/VladislavAntonyuk/MauiSamples/blob/main/CardLayout/CardsLayout.cs#L86 Replace PanGestureRecognizer with SwipeGestureRecognizer. PanGestureRecognizer fires events but SwipeGestureRecognizer doesn't. https://github.com/dotnet/maui/issues/7403#issuecomment-1172064417
https://github.com/ne0rrmatrix/SwipeGesturesSample.git
The repro link seems not to be working, could you update it?
Fixed link. https://github.com/ne0rrmatrix/MediaPlayerBugSwipeGestures for bug.
This is sample of it working without media elements. https://github.com/ne0rrmatrix/SwipeGesturesSample
Unfortunately I don't think in my case it is a bug. I have found out that exoplayer blocks swipe gestures by choice and it will not be changed. It was mentioned in closed bug report as working as intended. So you can ignore my comment as exoplayer in communitytoolkit is behaving as intended. It just overrides maui handler and blocks it.
Verified this on Visual Studio Enterprise 17.6.0 Preview 6.0. This issue does not repro on Android emulator (13.0-API 33) with below Project. MauiApp7.zip
Hi @Symbai. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.
You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@jfversluis @jsuarezruiz @AnnYang01 please reopen it. the issue still reproduces (version 7.0.86) https://github.com/VladislavAntonyuk/MauiSamples/blob/main/CardLayout
Also reproduced on maccatalyst