protected override Task <bool> PushRoot(NavigationPushInfo pushInfo)
        {
            var newPage    = GetInitializedPage(pushInfo);
            var navigation = GetRootNavigation();

            Device.BeginInvokeOnMainThread(async() => {
                try {
                    if (navigation.NavigationStack.Any())
                    {
                        while (navigation.ModalStack.Count > 0)
                        {
                            var page = await navigation.PopModalAsync(true);
                            DisposeModalPage(page);
                        }

                        var hasBackButton = NavigationPage.GetHasBackButton(newPage);
                        NavigationPage.SetHasBackButton(newPage, false);
                        await navigation.PushAsync(newPage);

                        foreach (var page in navigation.NavigationStack.Where(p => p != newPage).ToList())
                        {
                            navigation.RemovePage(page);
                        }

                        NavigationPage.SetHasBackButton(newPage, hasBackButton);
                    }
                    pushInfo.OnCompletedTask?.TrySetResult(true);
                }
                catch (Exception e) {
                    Console.WriteLine(e);
                    pushInfo.OnCompletedTask?.TrySetResult(false);
                }
            });
            return(pushInfo.OnCompletedTask?.Task);
        }
 void PushCallback(NavigationPushInfo pushInfo)
 {
     if (pushInfo == null)
     {
         throw new ArgumentNullException(nameof(pushInfo));
     }
     Push(pushInfo);
 }
        public virtual Page GetInitializedPage(NavigationPushInfo navigationPushInfo)
        {
            var page      = GetPage(navigationPushInfo.To?.ToString());
            var viewModel = GetViewModel(navigationPushInfo.To?.ToString());

            viewModel.NavigationParams = navigationPushInfo.NavigationParams;
            page.BindingContext        = viewModel;
            return(page);
        }
        protected override Task <bool> PushNormal(NavigationPushInfo pushInfo)
        {
            var newPage       = GetInitializedPage(pushInfo);
            var topNavigation = GetPickNavigation();

            Device.BeginInvokeOnMainThread(async() => {
                try {
                    await topNavigation.PushAsync(newPage);
                    pushInfo.OnCompletedTask?.TrySetResult(true);
                }
                catch (Exception e) {
                    Console.WriteLine(e);
                    pushInfo.OnCompletedTask?.TrySetResult(false);
                }
            });
            return(pushInfo.OnCompletedTask?.Task);
        }
        public virtual Task Push(NavigationPushInfo pushInfo)
        {
            switch (pushInfo.Mode)
            {
            case NavigationMode.Normal:
                return(PushNormal(pushInfo));

            case NavigationMode.Modal:
                return(PushModal(pushInfo));

            case NavigationMode.Custom:
                return(PushCustom(pushInfo));

            case NavigationMode.Root:
                return(PushRoot(pushInfo));

            case NavigationMode.PopUp:
                return(PushPopUp(pushInfo));

            default:
                throw new NotImplementedException();
            }
        }
        protected override Task <bool> PushModal(NavigationPushInfo pushInfo)
        {
            var newPage       = GetInitializedPage(pushInfo);
            var topNavigation = GetRootNavigation();

            Device.BeginInvokeOnMainThread(async() => {
                try {
                    if (pushInfo.Argument is bool modalWithNavigation && modalWithNavigation)
                    {
                        await topNavigation.PushModalAsync(new NavigationPage(newPage));
                    }
                    else
                    {
                        await topNavigation.PushModalAsync(newPage);
                    }

                    pushInfo.OnCompletedTask?.TrySetResult(true);
                }
                catch (Exception e) {
                    Trace.WriteLine(e);
                    pushInfo.OnCompletedTask?.TrySetResult(false);
                }
            });
 protected abstract Task <bool> PushModal(NavigationPushInfo pushInfo);
 protected abstract Task <bool> PushRoot(NavigationPushInfo pushInfo);
 protected abstract Task <bool> PushCustom(NavigationPushInfo pushInfo);
 protected abstract Task <bool> PushPopUp(NavigationPushInfo pushInfo);
 public abstract Page SetRoot(NavigationPushInfo pushInfo);
 protected override Task <bool> PushCustom(NavigationPushInfo pushInfo)
 {
     pushInfo.OnCompletedTask?.TrySetResult(false);
     return(pushInfo.OnCompletedTask?.Task);
 }
 public override Page SetRoot(NavigationPushInfo pushInfo)
 {
     RootPage = new NavigationPage(GetInitializedPage(pushInfo));
     return(RootPage);
 }