//https://stackoverflow.com/a/26569703/1981314
        void HandleRecognizer(UIScreenEdgePanGestureRecognizer recognizer, UINavigationController navigationController)
        {
            var translate = recognizer.TranslationInView(recognizer.View);
            var percent   = translate.X / recognizer.View.Bounds.Width * 2;
            var velocity  = recognizer.VelocityInView(recognizer.View);

            if (percent > 1)
            {
                percent = 1;
            }

            if (recognizer.State == UIGestureRecognizerState.Began)
            {
                interactor = new UIPercentDrivenInteractiveTransition();
                navigationController.PopViewController(true);
            }

            else if (recognizer.State == UIGestureRecognizerState.Changed)
            {
                interactor.UpdateInteractiveTransition(percent);
            }

            else if (recognizer.State == UIGestureRecognizerState.Ended)
            {
                if (percent > 0.5 || velocity.X > 0)
                {
                    interactor.FinishInteractiveTransition();
                }
                else
                {
                    interactor.CancelInteractiveTransition();
                }
                interactor = null;
            }
        }
Ejemplo n.º 2
0
        void InteractiveTransitionRecognizerAction(UIScreenEdgePanGestureRecognizer sender, IReadOnlyList <Page> pageStack)
        {
            var percent = sender.TranslationInView(sender.View).X / sender.View.Frame.Width;
            var finishTransitionOnEnd = percent > 0.5 || sender.VelocityInView(sender.View).X > 300;

            _renderer.EdgeGesturePanned(new EdgeGesturePannedArgs
            {
                State   = sender.State,
                Percent = percent,
                FinishTransitionOnEnd = finishTransitionOnEnd
            });

            switch (sender.State)
            {
            case UIGestureRecognizerState.Began:
                _renderer.PercentDrivenInteractiveTransition = new UIPercentDrivenInteractiveTransition();
                ((UINavigationController)_renderer).PopViewController(true);
                break;

            case UIGestureRecognizerState.Changed:
                _renderer.PercentDrivenInteractiveTransition.UpdateInteractiveTransition(percent);
                break;

            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Failed:
                _renderer.PercentDrivenInteractiveTransition.CancelInteractiveTransition();
                _renderer.PercentDrivenInteractiveTransition = null;
                break;

            case UIGestureRecognizerState.Ended:
                if (finishTransitionOnEnd)
                {
                    _renderer.PercentDrivenInteractiveTransition.FinishInteractiveTransition();

                    /*
                     * IMPORTANT!
                     *
                     * at the end of this transition, we need to check if we want a normal pop gesture or the custom one for the new page
                     * as we said before, the custom pop gesture doesnt play well with "normal" pages.
                     * So, at the end of the transition, we check if a page exists before the one we are opening and then check the mapstack
                     * If the previous page of the pop destination doesnt have shared transitions, we remove our custom gesture
                     */
                    var pageCount = pageStack.Count;
                    if (pageCount > 2 && _renderer.TransitionMap.GetMap(pageStack[pageCount - 3], null).Count == 0)
                    {
                        RemoveInteractiveTransitionRecognizer();
                    }
                }
                else
                {
                    _renderer.PercentDrivenInteractiveTransition.CancelInteractiveTransition();
                }
                _renderer.PercentDrivenInteractiveTransition = null;
                break;
            }
        }