async Task InvokeSwipe(CancellationToken cancellationToken)
        {
            try
            {
                await Task.Delay(100);

                if (!cancellationToken.IsCancellationRequested)
                {
                    if (SwipeRight)
                    {
                        SwipedRight?.Invoke(this, null);
                    }
                    else if (SwipeLeft)
                    {
                        SwipedLeft?.Invoke(this, null);
                    }
                    else
                    {
                        SmoothScrollTo(((View)Parent).Width, 0);
                    }
                }
            }
            catch (TaskCanceledException ex)
            {
            }
            catch (Exception ex)
            {
            }
        }
 public SwipeGestureRecognizer()
 {
     PanUpdated += (_, e) =>
     {
         if (e.StatusType == GestureStatus.Running)
         {
             translatedX = e.TotalX;
             translatedY = e.TotalY;
         }
         else if (e.StatusType == GestureStatus.Completed)
         {
             if (translatedX < 0 && Math.Abs(translatedX) > Math.Abs(translatedY))
             {
                 SwipedLeft?.Invoke();
             }
             else if (translatedX > 0 && translatedX > Math.Abs(translatedY))
             {
                 SwipedRight?.Invoke();
             }
             else if (translatedY < 0 && Math.Abs(translatedY) > Math.Abs(translatedX))
             {
                 SwipedUp?.Invoke();
             }
             else if (translatedY > 0 && translatedY > Math.Abs(translatedX))
             {
                 SwipedDown?.Invoke();
             }
         }
     };
 }
Beispiel #3
0
        public override bool OnFling(MotionEvent?e1, MotionEvent?e2, float velocityX, float velocityY)
        {
            var result = false;

            if (e1 == null || e2 == null)
            {
                return(result);
            }

            try
            {
                var diffY = e2.GetY() - e1.GetY();
                var diffX = e2.GetX() - e1.GetX();

                if (Math.Abs(diffX) > Math.Abs(diffY))
                {
                    if (Math.Abs(diffX) > SwipeThreshold && Math.Abs(velocityX) > SwipeVelocityThreshold)
                    {
                        if (diffX > 0)
                        {
                            SwipedRight?.Invoke(this, EventArgs.Empty);
                        }
                        else
                        {
                            SwipedLeft?.Invoke(this, EventArgs.Empty);
                        }

                        result = true;
                    }
                }
                else if (Math.Abs(diffY) > SwipeThreshold && Math.Abs(velocityY) > SwipeVelocityThreshold)
                {
                    if (diffY > 0)
                    {
                        SwipedBottom?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        SwipedTop?.Invoke(this, EventArgs.Empty);
                    }

                    result = true;
                }
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception);
            }

            return(result);
        }
        private void SwipeRelativeLayout_ScrollStopped(object sender, EventArgs e)
        {
            var scroll = (SwipeLayout)sender;

            if (scroll.ScrollX < scroll.Width / 2)
            {
                //swiperight
                SwipedRight?.Invoke(sender, e);
            }
            else if (scroll.ScrollX > scroll.Width * 1.5)
            {
                //swipeleft
                SwipedLeft?.Invoke(sender, e);
            }
        }
 protected virtual void OnSwipedRight(double x, double y)
 => SwipedRight?.Invoke(this, new SwipedEventArgs(_view, x, y));
 public void OnSwipeRight() => SwipedRight?.Invoke(this, EventArgs.Empty);
Beispiel #7
0
 public void RaiseSwipedRight()
 {
     SwipedRight?.Invoke(this, new EventArgs());
 }