Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ public void UpdateLongPressSettings()

public override bool OnTouchEvent(MotionEvent ev)
{
if (base.OnTouchEvent(ev))
return true;
var handled = base.OnTouchEvent(ev);

if (_pointerGestureHandler != null && ev?.Action is
MotionEventActions.Up or MotionEventActions.Down or MotionEventActions.Cancel)
{
_pointerGestureHandler.OnTouch(ev);
}

// Always call EndScrolling on ACTION_UP to ensure swipe gestures are completed,
// regardless of whether the base gesture detector consumed the event.
// This fixes SwipeGestureRecognizer not working on scrollable views like CollectionView.
if (_listener != null && ev?.Action == MotionEventActions.Up)
_listener.EndScrolling();

return false;
return handled;
}

protected override void Dispose(bool disposing)
Expand Down
41 changes: 41 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue16624.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue16624"
Title="Issue16624">
<VerticalStackLayout Padding="10">
<Label x:Name="StatusLabel"
AutomationId="StatusLabel"
Text="Swipe left on the CollectionView to trigger the swipe gesture"
FontSize="14"
Margin="0,0,0,10" />

<CollectionView AutomationId="TestCollectionView"
HeightRequest="300"
BackgroundColor="LightGray">
<CollectionView.GestureRecognizers>
<SwipeGestureRecognizer Direction="Left" Swiped="SwipeGestureRecognizer_Swiped" />
<SwipeGestureRecognizer Direction="Right" Swiped="SwipeGestureRecognizer_Swiped" />
</CollectionView.GestureRecognizers>
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Item 1</x:String>
<x:String>Item 2</x:String>
<x:String>Item 3</x:String>
<x:String>Item 4</x:String>
<x:String>Item 5</x:String>
<x:String>Item 6</x:String>
<x:String>Item 7</x:String>
<x:String>Item 8</x:String>
<x:String>Item 9</x:String>
<x:String>Item 10</x:String>
</x:Array>
</CollectionView.ItemsSource>
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding}" Padding="10" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ContentPage>
15 changes: 15 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue16624.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 16624, "SwipeGesture is not working on a ListView/CollectionView", PlatformAffected.Android)]
public partial class Issue16624 : ContentPage
{
public Issue16624()
{
InitializeComponent();
}

private void SwipeGestureRecognizer_Swiped(object sender, SwipedEventArgs e)
{
StatusLabel.Text = $"Swiped {e.Direction}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#if ANDROID
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue16624 : _IssuesUITest
{
public Issue16624(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "SwipeGesture is not working on a ListView/CollectionView";

[Test]
[Category(UITestCategories.Gestures)]
public void SwipeGestureOnCollectionViewShouldWork()
{
// Wait for the page to load
App.WaitForElement("TestCollectionView");
App.WaitForElement("StatusLabel");

// Get the CollectionView element to perform swipe on
var collectionView = App.WaitForElement("TestCollectionView");
var rect = collectionView.GetRect();
var centerX = rect.X + rect.Width / 2;
var centerY = rect.Y + rect.Height / 2;

// Perform a left swipe on the CollectionView
App.DragCoordinates(centerX + 100, centerY, centerX - 100, centerY);

// Wait for the status label to update
App.WaitForElement("StatusLabel");

// Verify the swipe was detected
var statusLabel = App.WaitForElement("StatusLabel");
var labelText = statusLabel.GetText();

Assert.That(labelText, Does.Contain("Swiped"), "Swipe gesture should be detected on CollectionView");
}

[Test]
[Category(UITestCategories.Gestures)]
public void SwipeRightGestureOnCollectionViewShouldWork()
{
// Wait for the page to load
App.WaitForElement("TestCollectionView");
App.WaitForElement("StatusLabel");

// Get the CollectionView element to perform swipe on
var collectionView = App.WaitForElement("TestCollectionView");
var rect = collectionView.GetRect();
var centerX = rect.X + rect.Width / 2;
var centerY = rect.Y + rect.Height / 2;

// Perform a right swipe on the CollectionView
App.DragCoordinates(centerX - 100, centerY, centerX + 100, centerY);

// Wait for the status label to update
App.WaitForElement("StatusLabel");

// Verify the swipe was detected
var statusLabel = App.WaitForElement("StatusLabel");
var labelText = statusLabel.GetText();

Assert.That(labelText, Does.Contain("Swiped"), "Swipe gesture should be detected on CollectionView");
}
}
}
#endif
Loading