public static UIPanGestureRecognizer DismissBySwiping(this DismissableOnboardingStep step, TimeEntriesLogViewCell cell, Direction direction)
        {
            async void onGesture(UIPanGestureRecognizer recognizer)
            {
                var isOneTouch = recognizer.NumberOfTouches == 1;
                var isVisible  = await step.ShouldBeVisible.FirstAsync();

                var isInDesiredDirection = Sign(recognizer.VelocityInView(cell).X) == Sign((int)direction);

                if (isOneTouch && isVisible && isInDesiredDirection)
                {
                    step.Dismiss();
                }
            }

            var panGestureRecognizer = new UIPanGestureRecognizer(onGesture)
            {
                ShouldRecognizeSimultaneously = (a, b) => true
            };

            IDisposable visibilityDisposable = null;

            visibilityDisposable = step.ShouldBeVisible
                                   .Where(visible => visible == false)
                                   .ObserveOn(SynchronizationContext.Current)
                                   .Subscribe(_ =>
            {
                cell.RemoveGestureRecognizer(panGestureRecognizer);
                visibilityDisposable?.Dispose();
            });

            cell.AddGestureRecognizer(panGestureRecognizer);

            return(panGestureRecognizer);
        }
Exemplo n.º 2
0
        private void updateSwipeDismissGestures(TimeEntriesLogViewCell nextFirstTimeEntry)
        {
            if (swipeLeftGestureRecognizer != null)
            {
                firstTimeEntry?.RemoveGestureRecognizer(swipeLeftGestureRecognizer);
            }

            swipeLeftAnimationDisposable?.Dispose();
            swipeRightAnimationDisposable?.Dispose();

            if (nextFirstTimeEntry == null)
            {
                return;
            }

            swipeLeftAnimationDisposable  = swipeLeftStep.ManageSwipeActionAnimationOf(nextFirstTimeEntry, Direction.Left);
            swipeRightAnimationDisposable = swipeRightStep.ManageSwipeActionAnimationOf(nextFirstTimeEntry, Direction.Right);

            swipeLeftGestureRecognizer = swipeLeftStep.DismissBySwiping(nextFirstTimeEntry, Direction.Left);
        }