diff --git a/src/Controls/src/Core/SwipeGestureRecognizer.cs b/src/Controls/src/Core/SwipeGestureRecognizer.cs index 355a9a1bc03e..bc6dde376761 100644 --- a/src/Controls/src/Core/SwipeGestureRecognizer.cs +++ b/src/Controls/src/Core/SwipeGestureRecognizer.cs @@ -65,29 +65,47 @@ bool ISwipeGestureController.DetectSwipe(View sender, SwipeDirection direction) var detected = false; var threshold = Threshold; + var detectedDirection = (SwipeDirection)(0); + if (direction.IsLeft()) { - detected |= _totalX < -threshold; + if (_totalX < -threshold) + { + detected = true; + detectedDirection |= SwipeDirection.Left; + } } if (direction.IsRight()) { - detected |= _totalX > threshold; + if (_totalX > threshold) + { + detected = true; + detectedDirection |= SwipeDirection.Right; + } } if (direction.IsDown()) { - detected |= _totalY > threshold; + if (_totalY > threshold) + { + detected = true; + detectedDirection |= SwipeDirection.Down; + } } if (direction.IsUp()) { - detected |= _totalY < -threshold; + if (_totalY < -threshold) + { + detected = true; + detectedDirection |= SwipeDirection.Up; + } } if (detected) { - SendSwiped(sender, direction); + SendSwiped(sender, detectedDirection); } return detected; diff --git a/src/Controls/tests/Core.UnitTests/Gestures/SwipeGestureRecognizerTests.cs b/src/Controls/tests/Core.UnitTests/Gestures/SwipeGestureRecognizerTests.cs index 2903f99bf264..d1a22a4e9308 100644 --- a/src/Controls/tests/Core.UnitTests/Gestures/SwipeGestureRecognizerTests.cs +++ b/src/Controls/tests/Core.UnitTests/Gestures/SwipeGestureRecognizerTests.cs @@ -83,5 +83,39 @@ public void SwipeIgnoredIfBelowThresholdTest() ((ISwipeGestureController)swipe).DetectSwipe(view, SwipeDirection.Up); Assert.False(detected); } + + [Fact] + public void SwipedEventDirectionMatchesTotalXTestWithFlags() + { + var view = new View(); + var swipe = new SwipeGestureRecognizer(); + + SwipeDirection direction = SwipeDirection.Up; + swipe.Swiped += (object sender, SwipedEventArgs e) => + { + direction = e.Direction; + }; + + ((ISwipeGestureController)swipe).SendSwipe(view, totalX: -150, totalY: 10); + ((ISwipeGestureController)swipe).DetectSwipe(view, SwipeDirection.Left | SwipeDirection.Right); + Assert.Equal(SwipeDirection.Left, direction); + } + + [Fact] + public void SwipedEventDirectionMatchesTotalYTestWithFlags() + { + var view = new View(); + var swipe = new SwipeGestureRecognizer(); + + SwipeDirection direction = SwipeDirection.Left; + swipe.Swiped += (object sender, SwipedEventArgs e) => + { + direction = e.Direction; + }; + + ((ISwipeGestureController)swipe).SendSwipe(view, totalX: 10, totalY: -150); + ((ISwipeGestureController)swipe).DetectSwipe(view, SwipeDirection.Up | SwipeDirection.Down); + Assert.Equal(SwipeDirection.Up, direction); + } } } \ No newline at end of file