public override void Show(MvxViewModelRequest request)
        {
            //all backstack manipulations should be done BEFORE creating and displaying new view/viewmodel
            var clearBackStack = request.ParameterValues != null && request.ParameterValues.ContainsKey("clearBack");
            var goBackToView   = request.ParameterValues != null && request.ParameterValues.ContainsKey("goBack");

            if (goBackToView)
            {
                var requestedViewType    = ViewsContainer.GetViewType(request.ViewModelType);
                var currentBackStack     = MasterNavigationController.ViewControllers;
                var viewControllerToJump = currentBackStack.FirstOrDefault(v => v.GetType() == requestedViewType);
                if (viewControllerToJump != null)
                {
                    MasterNavigationController.PopToViewController(viewControllerToJump, true);
                    return;
                }
            }
            var controller     = this.CreateViewControllerFor(request);
            var viewController = (IMvxIosView)controller;

            if (viewController == null)
            {
                throw new MvxException("Passed in IMvxIosView is not a UIViewController");
            }

            base.Show(viewController);

            //prevent animations fail - delete after showing new page
            if (clearBackStack)
            {
                MasterNavigationController.SetViewControllers(new UIViewController[] { controller as UIViewController }, 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 bool PopViewControllersUntilViewModel(Type viewModelType)
 {
     for (int i = MasterNavigationController.ViewControllers.Length - 1; i >= 0; i--)
     {
         if (MasterNavigationController.ViewControllers[i] is MvxViewController mvc)
         {
             if (mvc.ViewModel.GetType() == viewModelType)
             {
                 MasterNavigationController.PopToViewController(mvc, false);
                 return(true);
             }
         }
     }
     return(false);
 }