void OnPanned(UIPanGestureRecognizer gr)
        {
            if (!_element.IsVisible)
            {
                return;
            }

            if (touchCount == 0)
            {
                touchCount++;
            }

            PanEventArgs panEventArgs = new iOSPanEventArgs(gr, (BaseGestureEventArgs)_lastPanArgs ?? _downGestureArgs);

            if (gr.State == UIGestureRecognizerState.Ended || gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed)
            {
                touchCount = 0;

                if (_lastPanArgs == null)
                {
                    return;
                }
                _lastPanArgs  = null;
                _pinching     = false;
                _rotating     = false;
                _panning      = false;
                _longPressing = false;

                Point velocity   = panEventArgs.Velocity;
                bool  xTriggered = Math.Abs(velocity.X) > Settings.SwipeVelocityThreshold.X;
                bool  yTriggered = Math.Abs(velocity.Y) > Settings.SwipeVelocityThreshold.Y;
                if (xTriggered || yTriggered)
                {
                    Direction direction = Direction.NotClear;
                    if (!yTriggered)
                    {
                        direction = ((velocity.X > 0.0) ? Direction.Right : Direction.Left);
                    }
                    else if (!xTriggered)
                    {
                        direction = ((velocity.Y > 0.0) ? Direction.Down : Direction.Up);
                    }
                    SwipeEventArgs args = new iOSSwipeEventArgs(gr, direction)
                    {
                        VelocityX = velocity.X,
                        VelocityY = velocity.Y
                    };
                    foreach (var listener in _listeners)
                    {
                        if (listener.HandlesSwiped)
                        {
                            args.Listener = listener;
                            listener.OnSwiped(args);
                            if (args.Handled)
                            {
                                break;
                            }
                        }
                    }
                }
                foreach (var listener in _listeners)
                {
                    if (listener.HandlesPanning || listener.HandlesPanned)
                    {
                        panEventArgs.Listener = listener;
                        listener.OnPanned(panEventArgs);
                        if (panEventArgs.Handled)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                _panning = true;
                foreach (var listener in _listeners)
                {
                    if (!panEventArgs.Equals(_lastPanArgs) && listener.HandlesPanning)
                    {
                        panEventArgs.Listener = listener;
                        listener.OnPanning(panEventArgs);
                        if (panEventArgs.Handled)
                        {
                            break;
                        }
                    }
                }
                _lastPanArgs = panEventArgs;
            }
        }
Exemplo n.º 2
0
        void OnPanned(UIPanGestureRecognizer gr)
        {
            if (!_element.IsVisible)
            {
                return;
            }
            if (touchCount == 0)
            {
                //System.Diagnostics.Debug.WriteLine("new _viewLocationAtOnDown");
                //System.Diagnostics.Debug.WriteLine("onPanned set _viewLocationAtOnDown");
                _viewLocationAtOnDown = ViewLocationInWindow(gr.View);
                touchCount++;
            }
            //System.Diagnostics.Debug.WriteLine("NativeGestureHandler.onPanned");
            PanEventArgs panEventArgs = new iOSPanEventArgs(gr, _lastPanArgs, _viewLocationAtOnDown);

            if (gr.State == UIGestureRecognizerState.Ended || gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed)
            {
                touchCount = 0;
                //System.Diagnostics.Debug.WriteLine("\tonPanned _touchCount=0 = [" + _touchCount + "]");
                //System.Diagnostics.Debug.WriteLine("\tend");
                if (_lastPanArgs == null)
                {
                    return;
                }
                _lastPanArgs  = null;
                _pinching     = false;
                _rotating     = false;
                _panning      = false;
                _longPressing = false;
                bool handled = false;
                foreach (var listener in _listeners)
                {
                    //if (handled)
                    //	break;
                    if (listener.HandlesSwiped)
                    {
                        Point velocity   = panEventArgs.Velocity;
                        bool  xTriggered = Math.Abs(velocity.X) > Settings.SwipeVelocityThreshold.X;
                        bool  yTriggered = Math.Abs(velocity.Y) > Settings.SwipeVelocityThreshold.Y;
                        if (xTriggered || yTriggered)
                        {
                            Direction direction = Direction.NotClear;
                            if (!yTriggered)
                            {
                                direction = ((velocity.X > 0.0) ? Direction.Right : Direction.Left);
                            }
                            else if (!xTriggered)
                            {
                                direction = ((velocity.Y > 0.0) ? Direction.Down : Direction.Up);
                            }
                            SwipeEventArgs args = new iOSSwipeEventArgs(gr, direction, _viewLocationAtOnDown);
                            args.Listener  = listener;
                            args.VelocityX = velocity.X;
                            args.VelocityY = velocity.Y;
                            listener.OnSwiped(args);
                            //gr.CancelsTouchesInView = swipeEventArgs.Handled;
                            //return;
                            handled = handled || args.Handled;
                            if (handled)
                            {
                                break;
                            }
                        }
                    }
                }
                //gr.CancelsTouchesInView = handled;
                //if (handled)
                //	return;
                foreach (var listener in _listeners)
                {
                    //if (handled)
                    //	break;
                    if (listener.HandlesPanning || listener.HandlesPanned)
                    {
                        var taskArgs = new PanEventArgs(panEventArgs);
                        taskArgs.Listener = listener;
                        listener.OnPanned(taskArgs);
                        //gr.CancelsTouchesInView = panEventArgs.Handled;
                        //return;
                        handled = handled || taskArgs.Handled;
                        if (handled)
                        {
                            break;
                        }
                    }
                }
                //gr.CancelsTouchesInView = handled;
                //if (handled)
                //	return;
            }
            else
            {
                //System.Diagnostics.Debug.WriteLine("\tmove");
                _panning = true;
                bool handled = false;
                foreach (var listener in _listeners)
                {
                    //System.Diagnostics.Debug.WriteLine("\tlistener.handlesPanning=["+listener.HandlesPanning+"]");
                    //if (handled)
                    //	break;
                    if (!panEventArgs.Equals(_lastPanArgs) && listener.HandlesPanning)
                    {
                        var taskArgs = new PanEventArgs(panEventArgs);
                        taskArgs.Listener = listener;
                        listener.OnPanning(taskArgs);
                        handled = handled || taskArgs.Handled;
                        if (handled)
                        {
                            break;
                        }
                    }
                }
                //gr.CancelsTouchesInView = handled;
                _lastPanArgs = panEventArgs;
                //System.Diagnostics.Debug.WriteLine("_viewLocationAtOnDown ["+_viewLocationAtOnDown+"]");
            }
        }