summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-10-04 16:43:44 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-10-04 16:43:44 (GMT)
commitc83c19f106162ca55ab57dfea3693246ec6155fa (patch)
tree5ccb4da39788c578524ac072c6d3fda757b4e088 /Xamarin.Forms.Platform.Android
parent47b61aab59e52832ff65d0a1aaeafb9dceeaca64 (diff)
downloadxamarin-forms-c83c19f106162ca55ab57dfea3693246ec6155fa.zip
xamarin-forms-c83c19f106162ca55ab57dfea3693246ec6155fa.tar.gz
xamarin-forms-c83c19f106162ca55ab57dfea3693246ec6155fa.tar.bz2
[A] PanGestureRecognizer will consistently send Started/Move event (#389)
* Add reproduction for Bugzilla 39768 * [A] Handle onTouchEvent MOVE
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/InnerGestureListener.cs45
1 files changed, 35 insertions, 10 deletions
diff --git a/Xamarin.Forms.Platform.Android/InnerGestureListener.cs b/Xamarin.Forms.Platform.Android/InnerGestureListener.cs
index 8611af2..aadb628 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)