summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-10-04 09:43:44 -0700
committerJason Smith <jason.smith@xamarin.com>2016-10-04 09:43:44 -0700
commitc83c19f106162ca55ab57dfea3693246ec6155fa (patch)
tree5ccb4da39788c578524ac072c6d3fda757b4e088
parent47b61aab59e52832ff65d0a1aaeafb9dceeaca64 (diff)
downloadxamarin-forms-c83c19f106162ca55ab57dfea3693246ec6155fa.tar.gz
xamarin-forms-c83c19f106162ca55ab57dfea3693246ec6155fa.tar.bz2
xamarin-forms-c83c19f106162ca55ab57dfea3693246ec6155fa.zip
[A] PanGestureRecognizer will consistently send Started/Move event (#389)
* Add reproduction for Bugzilla 39768 * [A] Handle onTouchEvent MOVE
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39768.cs87
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Platform.Android/InnerGestureListener.cs45
3 files changed, 123 insertions, 10 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39768.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39768.cs
new file mode 100644
index 00000000..ae365782
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39768.cs
@@ -0,0 +1,87 @@
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+using System;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 39768, "PanGestureRecognizer sometimes won't fire completed event when dragging very slowly")]
+ public class Bugzilla39768 : TestContentPage
+ {
+ Image _Image;
+ Label _Label;
+ const string ImageName = "image";
+
+ [Preserve(AllMembers = true)]
+ public class PanContainer : ContentView
+ {
+ double x, y;
+
+ public EventHandler<PanUpdatedEventArgs> Panning;
+ public EventHandler<PanUpdatedEventArgs> PanningCompleted;
+
+ public PanContainer()
+ {
+ var panGesture = new PanGestureRecognizer();
+ panGesture.PanUpdated += OnPanUpdated;
+ GestureRecognizers.Add(panGesture);
+ }
+
+ void OnPanUpdated(object sender, PanUpdatedEventArgs e)
+ {
+ switch (e.StatusType)
+ {
+ case GestureStatus.Started:
+ break;
+
+ case GestureStatus.Running:
+ Content.TranslationX = x + e.TotalX;
+ Content.TranslationY = y + e.TotalY;
+
+ Panning?.Invoke(sender, e);
+ break;
+
+ case GestureStatus.Completed:
+ x = Content.TranslationX;
+ y = Content.TranslationY;
+
+ PanningCompleted?.Invoke(sender, e);
+ break;
+ }
+ }
+ }
+
+ protected override void Init()
+ {
+ _Image = new Image { Source = ImageSource.FromFile("crimson.jpg"), WidthRequest = 350, HeightRequest = 350, AutomationId = ImageName };
+ _Label = new Label { Text = "Press and hold the image for 1 second without moving it, then attempt to drag the image. If the image does not move, this test has failed. If this label does not display 'Success' when you have finished the pan, this test has failed." };
+
+ var panView = new PanContainer()
+ {
+ Content = _Image,
+ Panning = (s, e) =>
+ {
+ _Label.Text = $"TotalX: {e.TotalX}, TotalY: {e.TotalY}";
+ },
+ PanningCompleted = (s, e) =>
+ {
+ _Label.Text = "Success";
+ }
+ };
+
+ Content = new StackLayout
+ {
+ Children = {
+
+ panView,
+ _Label
+ }
+ };
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 670f286c..eb9424b6 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -184,6 +184,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43214.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42602.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43161.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39768.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41271.cs" />
<Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />
diff --git a/Xamarin.Forms.Platform.Android/InnerGestureListener.cs b/Xamarin.Forms.Platform.Android/InnerGestureListener.cs
index 8611af2d..aadb6288 100644
--- a/Xamarin.Forms.Platform.Android/InnerGestureListener.cs
+++ b/Xamarin.Forms.Platform.Android/InnerGestureListener.cs
@@ -9,7 +9,10 @@ namespace Xamarin.Forms.Platform.Android
{
internal class InnerGestureListener : Object, GestureDetector.IOnGestureListener, GestureDetector.IOnDoubleTapListener
{
- bool _isScrolling;
+ bool _isScrolling;
+ float _lastX;
+ float _lastY;
+
Func<bool> _scrollCompleteDelegate;
Func<float, float, int, bool> _scrollDelegate;
Func<int, bool> _scrollStartedDelegate;
@@ -48,6 +51,10 @@ namespace Xamarin.Forms.Platform.Android
{
if (e.Action == MotionEventActions.Up)
EndScrolling();
+ else if (e.Action == MotionEventActions.Down)
+ SetStartingPosition(e);
+ else if (e.Action == MotionEventActions.Move)
+ StartScrolling(e);
}
bool GestureDetector.IOnDoubleTapListener.OnDoubleTap(MotionEvent e)
@@ -76,6 +83,7 @@ namespace Xamarin.Forms.Platform.Android
bool GestureDetector.IOnGestureListener.OnDown(MotionEvent e)
{
+ SetStartingPosition(e);
return false;
}
@@ -88,22 +96,17 @@ namespace Xamarin.Forms.Platform.Android
void GestureDetector.IOnGestureListener.OnLongPress(MotionEvent e)
{
+ SetStartingPosition(e);
}
bool GestureDetector.IOnGestureListener.OnScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
- if (_scrollDelegate == null || e1 == null || e2 == null)
+ if (e1 == null || e2 == null)
return false;
- if (!_isScrolling && _scrollStartedDelegate != null)
- _scrollStartedDelegate(e2.PointerCount);
-
- _isScrolling = true;
-
- float totalX = e2.GetX() - e1.GetX();
- float totalY = e2.GetY() - e1.GetY();
+ SetStartingPosition(e1);
- return _scrollDelegate(totalX, totalY, e2.PointerCount);
+ return StartScrolling(e2);
}
void GestureDetector.IOnGestureListener.OnShowPress(MotionEvent e)
@@ -136,6 +139,28 @@ namespace Xamarin.Forms.Platform.Android
base.Dispose(disposing);
}
+ void SetStartingPosition(MotionEvent e1)
+ {
+ _lastX = e1.GetX();
+ _lastY = e1.GetY();
+ }
+
+ bool StartScrolling(MotionEvent e2)
+ {
+ if (_scrollDelegate == null)
+ return false;
+
+ if (!_isScrolling && _scrollStartedDelegate != null)
+ _scrollStartedDelegate(e2.PointerCount);
+
+ _isScrolling = true;
+
+ float totalX = e2.GetX() - _lastX;
+ float totalY = e2.GetY() - _lastY;
+
+ return _scrollDelegate(totalX, totalY, e2.PointerCount);
+ }
+
void EndScrolling()
{
if (_isScrolling && _scrollCompleteDelegate != null)