/// <summary>
        /// Pops a page modally with the specified <paramref name="transitionEffect"/>.
        /// </summary>
        /// <param name="sender">Navigation.</param>
        /// <param name="transitionEffect">Transition type.</param>
        /// <param name="options">Transition options.</param>
        public static Task PopModalAsyncWithTransition(this INavigation sender, PageTransitionEffectType transitionEffect, TransitionOptions options = null)
        {
            var originPage = sender.ModalStack?.LastOrDefault() as ContentPage;

            if (originPage == null)
            {
                return(sender.PopModalAsync());
            }

            return(DependencyService.Get <INavigationTransitionService>().PopModalAsync(originPage, transitionEffect, options ?? new TransitionOptions()));
        }
        /// <summary>
        /// Pushes the page associated with the provided <paramref name="viewModel"/> and custom <paramref name="transitionEffect"/>.
        /// </summary>
        /// <param name="viewModel">View model.</param>
        /// <param name="transitionEffect">Transition effect.</param>
        /// <param name="options">Transition effect options.</param>
        public static Task PushWithTransitionAsync(BaseViewModel viewModel, PageTransitionEffectType transitionEffect, TransitionOptions options = null)
        {
            var destinationPage = BuildPage(viewModel, false);

            return(DependencyService.Get <INavigationTransitionService>().PushAsync(CurrentPage, destinationPage, transitionEffect, options));
        }
        /// <summary>
        /// Modally pushes the page associated with the provided <paramref name="viewModel"/> and custom <paramref name="transitionEffect"/>.
        /// </summary>
        /// <param name="viewModel">View model.</param>
        /// <param name="transitionEffect">Transition effect.</param>
        /// <param name="options">Transition effect options.</param>
        /// <param name="wrapInNavigation">If set to <c>true</c> wraps the page in a <see cref="NavigationPage"/> instance.</param>
        public static Task PushModalWithTransitionAsync(BaseViewModel viewModel, PageTransitionEffectType transitionEffect, TransitionOptions options = null, bool wrapInNavigation = true)
        {
            var destinationPage = BuildPage(viewModel, wrapInNavigation);

            return(DependencyService.Get <INavigationTransitionService>().PushModalAsync(CurrentPage, destinationPage, transitionEffect, options));
        }
 /// <summary>
 /// Modally pops the top Page from the navigation stack.
 /// </summary>
 /// <param name="transitionEffect">Transition effect.</param>
 /// <param name="options">Transition effect options.</param>
 public static Task PopModalWithTransitionAsync(PageTransitionEffectType transitionEffect, TransitionOptions options = null)
 {
     return(DependencyService.Get <INavigationTransitionService>().PopModalAsync(CurrentPage, transitionEffect, options));
 }
        public static IUIViewControllerAnimatedTransitioning GetTransition(bool isPushing, PageTransitionEffectType transitionEffect, TransitionOptions options)
        {
            BaseTransition transition = null;

            if (options == null)
            {
                options = new TransitionOptions();
            }

            if (isPushing)
            {
                switch (transitionEffect)
                {
                case PageTransitionEffectType.None:
                    return(null);

                case PageTransitionEffectType.Checkerboard:
                    transition = new CheckerBoardTransition();
                    break;

                case PageTransitionEffectType.ZoomFade:
                    transition = new ZoomFadeTransition();
                    break;

                case PageTransitionEffectType.Fade:
                    transition = new FadeTransition();
                    break;

                case PageTransitionEffectType.Swipe:
                    transition = new SwipeTransition();
                    ((SwipeTransition)transition).SwipeDirection = options.PushSwipeTransitionDirection;
                    break;

                case PageTransitionEffectType.DoorSlide:
                    transition = new DoorSlideTransition();
                    break;

                case PageTransitionEffectType.Fold:
                    transition = new FoldTransition();
                    break;

                case PageTransitionEffectType.Turn:
                    transition = new TurnTransition();
                    break;
                }

                transition.TransitionOperation = UINavigationControllerOperation.Push;
            }
            else
            {
                switch (transitionEffect)
                {
                case PageTransitionEffectType.None:
                    return(null);

                case PageTransitionEffectType.Checkerboard:
                    transition = new CheckerBoardTransition();
                    break;

                case PageTransitionEffectType.ZoomFade:
                    transition = new ZoomFadeTransition();
                    break;

                case PageTransitionEffectType.Fade:
                    transition = new FadeTransition();
                    break;

                case PageTransitionEffectType.Swipe:
                    transition = new SwipeTransition();
                    ((SwipeTransition)transition).SwipeDirection             = options.PopSwipeTransitionDirection;
                    ((SwipeTransition)transition).ApplyPopTransitionToOrigin = options.EnablePopSwipeTransition;

                    break;

                case PageTransitionEffectType.DoorSlide:
                    transition = new DoorSlideTransition();
                    ((DoorSlideTransition)transition).ApplyPopTransitionToOrigin = options.EnablePopSwipeTransition;

                    break;

                case PageTransitionEffectType.Fold:
                    transition = new FoldTransition();
                    break;

                case PageTransitionEffectType.Turn:
                    transition = new TurnTransition();
                    break;
                }

                transition.TransitionOperation = UINavigationControllerOperation.Pop;
            }

            transition.Duration             = options.TransitionDuration;
            transition.ToHasNavigationBar   = options.DestinationPageHasNavigationBar;
            transition.FromHasNavigationBar = options.SourcePageHasNavigationBar;

            return(transition);
        }
        public async Task PopModalAsync(Page originPage, PageTransitionEffectType transitionEffect, TransitionOptions options = null)
        {
            var nativeOriginPage = originPage.GetNativeController();

            var transitionDelegate = new ViewControllerTransitioningDelegate()
            {
                TransitionType = transitionEffect,
                Options        = options
            };

            nativeOriginPage.TransitioningDelegate = transitionDelegate;

            await originPage.Navigation.PopModalAsync();
        }
        //Does not currently animate the transition. PR has been merged. Waiting for release.
        public async Task PushModalAsync(Page originPage, Page destinationPage, PageTransitionEffectType transitionEffect, TransitionOptions options = null)
        {
            var nativeDest = destinationPage.GetNativeController();

            var transitionDelegate = new ViewControllerTransitioningDelegate()
            {
                TransitionType = transitionEffect,
                Options        = options
            };

            nativeDest.ModalPresentationStyle = UIModalPresentationStyle.Custom;

            nativeDest.TransitioningDelegate = transitionDelegate;

            await originPage.Navigation.PushModalAsync(destinationPage);
        }
        public async Task PopAsync(Page originPage, PageTransitionEffectType transitionEffect, TransitionOptions options = null)
        {
            var nativeOriginPage = originPage.GetNativeController();

            var navigationController = nativeOriginPage.NavigationController;

            var transitionDelegate = new NavigationDelegate()
            {
                TransitionType = transitionEffect,
                Options        = options
            };

            navigationController.Delegate = transitionDelegate;

            await originPage.Navigation.PopAsync();

            navigationController.Delegate = null;
        }