Example #1
0
        void moveWithDuration(double duration, SwipeTableViewCellDirection direction)
        {
            isExited = true;
            nfloat origin = 0.0F;

            if (direction == SwipeTableViewCellDirection.Left)
            {
                origin = cell.Bounds.Width.Neg();
            }
            else if (direction == SwipeTableViewCellDirection.Right)
            {
                origin = cell.Bounds.Width;
            }

            var percentage = percentageWithOffset(origin, cell.Bounds.Width);
            var frame      = contentScreenshotView.Frame;

            frame.X = origin;

            // Color
            UIColor color = colorWithPercentage((nfloat)currentPercentage);

            if (color != null)
            {
                colorIndicatorView.BackgroundColor = color;
            }

            UIView.Animate(
                duration,
                0,
                UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.AllowUserInteraction,
                () => {
                contentScreenshotView.Frame = frame;
                slidingView.Alpha           = 0;
                slideViewWithPercentage(percentage, activeView, ShouldAnimateIcons);
            },
                executeCompletionBlock
                );
        }
Example #2
0
        void handlePanGestureRecognizer()
        {
            if (!ShouldDrag || isExited)
            {
                return;
            }

            var state       = this.State;
            var translation = TranslationInView(cell);
            var velocity    = VelocityInView(cell);

            nfloat percentage;

            if (contentScreenshotView == null)
            {
                percentage = percentageWithOffset(0, cell.Bounds.Width);
            }
            else
            {
                percentage = percentageWithOffset(contentScreenshotView.Frame.X, cell.Bounds.Width);
            }

            var animationDuration = animationDurationWithVelocity(velocity);

            direction = directionWithPercentage(percentage);

            if (state == UIGestureRecognizerState.Began || state == UIGestureRecognizerState.Changed)
            {
                dragging = true;

                setupSwipingView();

                var center = new CGPoint(contentScreenshotView.Center.X + translation.X, contentScreenshotView.Center.Y);
                contentScreenshotView.Center = center;
                animateWithOffset(contentScreenshotView.Frame.GetMinX());
                SetTranslation(new CGPoint(0.0F, 0.0F), cell);

                // Notifying the handler that we are dragging with an offset percentage
                if (SwipeWithPercentage != null)
                {
                    SwipeWithPercentage(cell, percentage);
                }
            }
            else if (state == UIGestureRecognizerState.Ended || state == UIGestureRecognizerState.Cancelled)
            {
                dragging          = false;
                activeView        = viewWithPercentage(percentage);
                currentPercentage = percentage;

                SwipeTableViewCellState cellState = stateWithPercentage(percentage);
                SwipeTableCellMode      cellMode  = SwipeTableCellMode.None;

                if (cellState == SwipeTableViewCellState.StateRightShort && ModeForStateRightShort != SwipeTableCellMode.None)
                {
                    cellMode = ModeForStateRightShort;
                }
                else if (cellState == SwipeTableViewCellState.StateRightLong && ModeForStateRightLong != SwipeTableCellMode.None)
                {
                    cellMode = ModeForStateRightLong;
                }
                else if (cellState == SwipeTableViewCellState.StateLeftShort && ModeForStateLeftShort != SwipeTableCellMode.None)
                {
                    cellMode = ModeForStateLeftShort;
                }
                else if (cellState == SwipeTableViewCellState.StateLeftLong && ModeForStateLeftLong != SwipeTableCellMode.None)
                {
                    cellMode = ModeForStateLeftLong;
                }

                if (cellMode == SwipeTableCellMode.Exit && direction != SwipeTableViewCellDirection.Center)
                {
                    moveWithDuration(animationDuration, direction);
                }
                else
                {
                    swipeToOriginWithCompletion(executeCompletionBlock);
                }

                // We notify the handler that we just ended swiping.
                if (DidEndSwiping != null)
                {
                    DidEndSwiping(cell);
                }
            }
        }