Skip to content

Commit

Permalink
PanGesture notify Completed event moving outside View limits (#15700)
Browse files Browse the repository at this point in the history
* Fix the issue

* Added sample

* Fix the issue on Android

* Updated Impl

* Implement the changes also on iOS/Catalyst

* Revert changes on Android and iOS

* More changes

* Remove unnecessary changes

* Align Windows behavior with the test of the platforms

* Removed unnecessary changes

* Added UITest

* Removed test

* Added UITest
  • Loading branch information
jsuarezruiz authored Feb 2, 2024
1 parent 0ef0c03 commit aafaff3
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 10 deletions.
24 changes: 24 additions & 0 deletions src/Controls/samples/Controls.Sample.UITests/Issues/Issue5191.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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.Issue5191">
<Grid
RowDefinitions="*,*">
<Grid
BackgroundColor="Green">
<Grid.GestureRecognizers>
<PanGestureRecognizer
PanUpdated="OnPanGestureRecognizerUpdated" />
</Grid.GestureRecognizers>
<Label
x:Name="InfoLabel"
AutomationId="WaitForStubControl"
TextColor="White"/>
</Grid>
<Grid
Grid.Row="1"
BackgroundColor="Red">

</Grid>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Platform;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 5191, "PanGesture notify Completed event moving outside View limits", PlatformAffected.All)]
public partial class Issue5191 : ContentPage
{
public Issue5191()
{
InitializeComponent();
}

void OnPanGestureRecognizerUpdated(object sender, PanUpdatedEventArgs e)
{
InfoLabel.Text = $"StatusType: {e.StatusType}, TotalX: {e.TotalX}, TotalY: {e.TotalY}";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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.Pages.PanGestureEventsGallery"
Title="PanGesture Events Gallery">
<Grid
RowDefinitions="*,*">
<Grid
BackgroundColor="Green">
<Grid.GestureRecognizers>
<PanGestureRecognizer
PanUpdated="OnPanGestureRecognizerUpdated" />
</Grid.GestureRecognizers>
<Label
x:Name="InfoLabel"
TextColor="White"/>
</Grid>
<Grid
Grid.Row="1"
BackgroundColor="Red">

</Grid>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample.Pages
{
public partial class PanGestureEventsGallery : ContentPage
{
public PanGestureEventsGallery()
{
InitializeComponent();
}

void OnPanGestureRecognizerUpdated(object sender, PanUpdatedEventArgs e)
{
InfoLabel.Text = $"StatusType: {e.StatusType}, TotalX: {e.TotalX}, TotalY: {e.TotalY}";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Internals;

namespace Maui.Controls.Sample.Pages
{
[Preserve(AllMembers = true)]
public class PanGestureGallery : ContentPage
{
public PanGestureGallery()
{
var descriptionLabel =
new Label { Text = "PanGesture Galleries", Margin = new Thickness(2, 2, 2, 2) };

Title = "PanGesture Galleries";

Content = new ScrollView
{
Content = new StackLayout
{
Children =
{
descriptionLabel,
GalleryBuilder.NavButton("PanGesture Playground", () =>
new PanGesturePlaygroundGallery(), Navigation),
GalleryBuilder.NavButton("PanGesture Events Gallery", () =>
new PanGestureEventsGallery(), Navigation),
}
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
using Maui.Controls.Sample.Pages.Base;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Internals;

using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Pages
{
public class PanGestureGalleryPage : BasePage
public class PanGesturePlaygroundGallery : BasePage
{
public class PanCompleteArgs : EventArgs
{
Expand Down Expand Up @@ -120,8 +119,10 @@ PinchGestureRecognizer GetPinch()
}
}

public PanGestureGalleryPage()
public PanGesturePlaygroundGallery()
{
Title = "PanGesture Playground";

var box = new Image
{
BackgroundColor = Colors.Gray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
{
new SectionModel(typeof(DragAndDropBetweenLayouts), "Drag And Drop",
"Drag and Drop Views."),
new SectionModel(typeof(PanGestureGalleryPage), "Pan Gesture",
new SectionModel(typeof(PanGestureGallery), "Pan Gesture",
"Pan Gesture."),
new SectionModel(typeof(PinchGestureTestPage), "Pinch Gesture",
"Pinch Gesture."),
Expand All @@ -23,4 +23,4 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
"Tap Gesture."),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void HandlePan(ManipulationDeltaRoutedEventArgs e, View view)
{
if (view == null)
return;

_isPanning = true;

foreach (IPanGestureController recognizer in view.GestureRecognizers.GetGesturesFor<PanGestureRecognizer>().Where(g => g.TouchPoints == _fingers.Count))
Expand Down Expand Up @@ -440,8 +440,10 @@ void OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs
void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
var view = Element as View;

if (view == null)
return;

HandleSwipe(e, view);
HandlePinch(e, view);
HandlePan(e, view);
Expand All @@ -468,12 +470,15 @@ void OnPointerCanceled(object sender, PointerRoutedEventArgs e)

void OnPointerExited(object sender, PointerRoutedEventArgs e)
{
uint id = e.Pointer.PointerId;
if (_fingers.Contains(id))
_fingers.Remove(id);
if (!_isPanning)
{
uint id = e.Pointer.PointerId;
if (_fingers.Contains(id))
_fingers.Remove(id);
}

SwipeComplete(true);
PinchComplete(true);
PanComplete(true);
}

void OnPointerPressed(object sender, PointerRoutedEventArgs e)
Expand Down
30 changes: 30 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue5191.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.Maui.AppiumTests;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Controls.AppiumTests.Tests.Issues
{
public class Issue5191 : _IssuesUITest
{
public Issue5191(TestDevice device) : base(device) { }

public override string Issue => "PanGesture notify Completed event moving outside View limits";

[Test]
public void Issue5191Test()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.iOS, TestDevice.Mac, TestDevice.Windows },
"Android Test.");

App.WaitForElement("WaitForStubControl");

// 1. Drag and drop.
App.DragCoordinates(100, 500, 1000, 100);

// 2. Verify if PanGesture reports a completed event status when the touch is lifted.
var result = App.FindElement("WaitForStubControl").GetText();
Assert.True(result?.Contains("Completed", StringComparison.OrdinalIgnoreCase));
}
}
}

0 comments on commit aafaff3

Please sign in to comment.