Exemple #1
0
 public void ShowRoot()
 {
     if (!(GetCurrentViewModel() is HomeViewModel))
     {
         MasterNavigationController.PopToRootViewController(false);
     }
 }
Exemple #2
0
        public override void Show(MvxViewModelRequest request)
        {
            if (request.PresentationValues != null)
            {
                var viewCreator = GetViewCreator();

                // More info at:
                // - http://gregshackles.com/presenters-in-mvvmcross-using-presentation-values/
                // - https://gist.github.com/gshackles/5735595
                if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.CLEAR_STACK))
                {
                    var nextViewController = (UIViewController)viewCreator.CreateView(request);

                    if (MasterNavigationController.TopViewController.GetType() != nextViewController.GetType())
                    {
                        MasterNavigationController.PopToRootViewController(false);
                        MasterNavigationController.PushViewController(nextViewController, false);
                    }

                    return;
                }
                else if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.MAKE_IT_THE_FIRST_ONE))
                {
                    MasterNavigationController.SetViewControllers(new UIViewController[] { }, false);
                }
                else if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.BACK_OR_IN_PLACE))
                {
                    var nextViewController     = (UIViewController)viewCreator.CreateView(request);
                    var existingViewController =
                        MasterNavigationController.ViewControllers.FirstOrDefault(
                            vc => vc.GetType() == nextViewController.GetType() && vc != CurrentTopViewController);

                    if (existingViewController != null)
                    {
                        MasterNavigationController.PopToViewController(existingViewController, true);
                    }
                    else
                    {
                        var transition = new CATransition
                        {
                            Duration = 0.3,
                            Type     = CAAnimation.TransitionPush,
                            Subtype  = CAAnimation.TransitionFade
                        };

                        MasterNavigationController.PopViewController(false);
                        MasterNavigationController.View.Layer.AddAnimation(transition, null);
                        MasterNavigationController.PushViewController(nextViewController, false);
                    }

                    return;
                }
            }

            base.Show(request);
        }
Exemple #3
0
        private void clearStackAndNavigate(MvxViewModelRequest request)
        {
            var nextViewController = (UIViewController)ViewCreator.CreateView(request);

            if (MasterNavigationController.TopViewController.GetType() != nextViewController.GetType())
            {
                MasterNavigationController.PopToRootViewController(false);
                MasterNavigationController.ViewControllers = new UIViewController[] { nextViewController };
            }
        }
Exemple #4
0
        public override void Show(MvxViewModelRequest request)
        {
            if (request.PresentationValues != null)
            {
                if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.ClearStack))
                {
                    foreach (var vc in MasterNavigationController.ViewControllers)
                    {
                        vc.DismissViewController(true, null);
                    }

                    var nextViewController = this.CreateViewControllerFor(request) as UIViewController;

                    if (MasterNavigationController.TopViewController.GetType() != nextViewController.GetType())
                    {
                        MasterNavigationController.PopToRootViewController(false);
                        MasterNavigationController.PushViewController(nextViewController, false);
                    }

                    return;
                }

                if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.NoAnimation))
                {
                    var nextViewController = this.CreateViewControllerFor(request) as UIViewController;
                    MasterNavigationController.PushViewController(nextViewController, false);


                    return;
                }

                if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.TransitionLeftToRight))
                {
                    var nextViewController = this.CreateViewControllerFor(request) as UIViewController;
                    MasterNavigationController.PushControllerWithTransition(nextViewController, UIViewAnimationOptions.TransitionCurlDown);


                    return;
                }
            }
            base.Show(request);
        }
        public override void Show(MvxViewModelRequest request)
        {
            if (request.PresentationValues != null)
            {
                if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.ParkingReserved))
                {
                    var vc = MasterNavigationController.TopViewController;
                    while (!(vc is ParkingReservedView))
                    {
                        ReleaseTimerIfNeeded(vc);

                        MasterNavigationController.PopViewController(false);
                        //vc.Dispose();
                        vc = MasterNavigationController.TopViewController;
                    }
                    return;
                }
                else if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.Menu))
                {
                    var vc = MasterNavigationController.TopViewController;
                    while (!(vc is MenuView))
                    {
                        Console.WriteLine(vc);
                        ReleaseTimerIfNeeded(vc);

                        if (vc is ParkingSearchView)
                        {
                            MasterNavigationController.PopViewController(true);
                            return;
                        }
                        else
                        {
                            MasterNavigationController.PopViewController(false);
                        }

                        //vc.Dispose();
                        vc = MasterNavigationController.TopViewController;
                    }
                    return;
                }
                else if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.Search))
                {
                    var vc = MasterNavigationController.TopViewController;
                    while (!(vc is ParkingSearchView))
                    {
                        ReleaseTimerIfNeeded(vc);

                        MasterNavigationController.PopViewController(false);
                        //vc.Dispose();
                        vc = MasterNavigationController.TopViewController;
                    }
                    return;
                }
                else if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.ParkingList))
                {
                    var vc = MasterNavigationController.TopViewController;
                    while (!(vc is ParkingListsView) && !(vc is MyReservationsView))
                    {
                        ReleaseTimerIfNeeded(vc);

                        MasterNavigationController.PopViewController(false);
                        //vc.Dispose();
                        vc = MasterNavigationController.TopViewController;
                    }

                    return;
                }
                else if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.ClearStack))
                {
                    MasterNavigationController.PopToRootViewController(false);
                }
            }

            //prevent reshowing the current view controller (e.g 10 minutes before leaving )
            if (MasterNavigationController != null && MasterNavigationController.TopViewController != null)
            {
                var topvc = MasterNavigationController.TopViewController;
                if (topvc != null && topvc is MvxViewController && request.ViewModelType == (topvc as MvxViewController).ViewModel.GetType())
                {
                    return;
                }
            }

            base.Show(request);
        }
Exemple #6
0
        public override void Show(MvvmCross.Core.ViewModels.MvxViewModelRequest request)
        {
            if (request.PresentationValues != null)
            {
                #region ClearStack
                if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.ClearStack))
                {
                    MasterNavigationController.PopToRootViewController(false);
                    var nextViewController = (UIViewController)ViewCreator.CreateView(request);
                    MasterNavigationController.PushViewController(nextViewController, true);
                    return;
                }
                #endregion

                #region ShowBack
                if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.ShowBack))
                {
                    var  nextViewController    = (UIViewController)ViewCreator.CreateView(request);
                    var  currentViewController = MasterNavigationController.TopViewController;
                    bool animated = false;

                    while (!animated && currentViewController != null && currentViewController.GetType() != nextViewController.GetType())
                    {
                        if (MasterNavigationController.ViewControllers.Length > 1)
                        {
                            var backViewController = MasterNavigationController.ViewControllers[MasterNavigationController.ViewControllers.Length - 2];
                            if (backViewController.GetType() == nextViewController.GetType())
                            {
                                animated = true;
                            }
                        }
                        else
                        {
                            break;
                        }

                        MasterNavigationController.PopViewController(animated);

                        if (animated)
                        {
                            MemoryUtils.DelayReleaseObject(2000, currentViewController);
                        }
                        else
                        {
                            MemoryUtils.ReleaseObject(currentViewController);
                        }

                        currentViewController = MasterNavigationController.TopViewController;
                    }

                    if (MasterNavigationController.ViewControllers.Length <= 1)
                    {
                        MasterNavigationController.PushViewController(nextViewController, true);
                    }

                    return;
                }
                #endregion

                #region CloseCurrentAndShow
                if (request.PresentationValues.ContainsKey(PresentationBundleFlagKeys.CloseCurrentAndShow))
                {
                    // let make a async task to remove current from history to not make UI flash
                    System.Threading.Tasks.Task.Run(async() =>
                    {
                        await System.Threading.Tasks.Task.Delay(1000);

                        if (closeViewController == null)
                        {
                            return;
                        }
                        MasterNavigationController.InvokeOnMainThread(async() =>
                        {
                            //wait for until top view controller is showed
                            while (closeViewController != MasterNavigationController.TopViewController)
                            {
                                await System.Threading.Tasks.Task.Delay(100);
                            }

                            int countVc = MasterNavigationController.ViewControllers.Length;

                            if (countVc > 1)
                            {
                                UIViewController releaseViewController = MasterNavigationController.ViewControllers[countVc - 2];
                                UIViewController[] newHistory          = new UIViewController[countVc - 1];
                                for (int i = 0; i < countVc - 2; i++)
                                {
                                    newHistory[i] = MasterNavigationController.ViewControllers[i];
                                }
                                newHistory[countVc - 2] = MasterNavigationController.ViewControllers[countVc - 1];
                                MasterNavigationController.ViewControllers = newHistory;

                                MemoryUtils.ReleaseObject(releaseViewController);
                            }

                            closeViewController = null;
                        });
                    });
                }
                #endregion
            }
            base.Show(request);
        }