Ejemplo n.º 1
0
 protected void CleanupModalViewControllers()
 {
     while (ModalViewControllers.Any())
     {
         CloseModalViewController(ModalViewControllers.LastOrDefault());
     }
 }
Ejemplo n.º 2
0
        protected virtual bool CloseChildViewController(IMvxViewModel viewModel, MvxChildPresentationAttribute attribute)
        {
            // if there are modals presented
            if (ModalViewControllers.Any())
            {
                foreach (var modalNav in ModalViewControllers.Where(v => v is UINavigationController))
                {
                    if (TryCloseViewControllerInsideStack((UINavigationController)modalNav, viewModel))
                    {
                        return(true);
                    }
                }
            }

            //if the current root is a TabBarViewController, delegate close responsibility to it
            if (TabBarViewController != null && TabBarViewController.CloseChildViewModel(viewModel))
            {
                return(true);
            }

            if (SplitViewController != null && SplitViewController.CloseChildViewModel(viewModel))
            {
                return(true);
            }

            // if the current root is a NavigationController, close it in the stack
            if (MasterNavigationController != null && TryCloseViewControllerInsideStack(MasterNavigationController, viewModel))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        protected virtual ValueTask <bool> CloseModalViewController(IMvxViewModel viewModel)
        {
            if (ModalViewControllers == null || !ModalViewControllers.Any())
            {
                return(new ValueTask <bool>(false));
            }

            var modal = ModalViewControllers
                        .FirstOrDefault(v => v is IMvxTvosView && v.GetIMvxTvosView().ViewModel == viewModel);

            if (modal != null)
            {
                return(CloseModalViewController(modal));
            }

            UIViewController viewController = null;

            foreach (var vc in ModalViewControllers.Where(v => v is UINavigationController))
            {
                var rootViewController = ((UINavigationController)vc).ViewControllers.FirstOrDefault();
                if (rootViewController != null && rootViewController.GetIMvxTvosView().ViewModel == viewModel)
                {
                    viewController = vc;
                    break;
                }
            }
            if (viewController != null)
            {
                return(CloseModalViewController(viewController));
            }

            return(new ValueTask <bool>(false));
        }
Ejemplo n.º 4
0
        public override void Close(IMvxViewModel toClose)
        {
            // check if there is a modal presented
            if (ModalViewControllers.Any() && CloseModalViewController(toClose))
            {
                return;
            }

            // if the current root is a TabBarViewController, delegate close responsibility to it
            if (TabBarViewController != null && TabBarViewController.CloseChildViewModel(toClose))
            {
                return;
            }

            // if the current root is a SplitViewController, delegate close responsibility to it
            if (SplitViewController != null && SplitViewController.CloseChildViewModel(toClose))
            {
                return;
            }

            // if the current root is a NavigationController, close it in the stack
            if (MasterNavigationController != null && TryCloseViewControllerInsideStack(MasterNavigationController, toClose))
            {
                return;
            }

            MvxTrace.Warning($"Could not close ViewModel type {toClose.GetType().Name}");
        }
Ejemplo n.º 5
0
        protected virtual ValueTask <bool> ShowChildViewController(UIViewController viewController,
                                                                   MvxChildPresentationAttribute attribute,
                                                                   MvxViewModelRequest request)
        {
            if (viewController is MvxSplitViewController)
            {
                throw new MvxException("A SplitViewController can't be present in a child.  Consider using a Root instead.");
            }

            if (ModalViewControllers.Any())
            {
                if (ModalViewControllers.LastOrDefault() is UINavigationController navigationController)
                {
                    PushViewControllerIntoStack(navigationController, viewController, attribute.Animated);
                    return(new ValueTask <bool>(true));
                }
                else
                {
                    throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is currently a plain modal view presented!");
                }
            }

            if (TabBarViewController != null && TabBarViewController.ShowChildView(viewController))
            {
                return(new ValueTask <bool>(true));
            }

            if (MasterNavigationController != null)
            {
                PushViewControllerIntoStack(MasterNavigationController, viewController, attribute.Animated);
                return(new ValueTask <bool>(true));
            }

            throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is no current stack!");
        }
Ejemplo n.º 6
0
        protected virtual ValueTask <bool> CloseChildViewController(IMvxViewModel viewModel, MvxChildPresentationAttribute?attribute)
        {
            if (ModalViewControllers.Any())
            {
                foreach (var navController in ModalViewControllers.Where(v => v is UINavigationController))
                {
                    if (TryCloseViewControllerInsideStack((UINavigationController)navController, viewModel))
                    {
                        return(new ValueTask <bool>(true));
                    }
                }
            }

            if (TabBarViewController != null && TabBarViewController.CloseChildViewModel(viewModel))
            {
                return(new ValueTask <bool>(true));
            }

            if (MasterNavigationController != null && TryCloseViewControllerInsideStack(MasterNavigationController, viewModel))
            {
                return(new ValueTask <bool>(true));
            }

            return(new ValueTask <bool>(false));
        }
Ejemplo n.º 7
0
        protected virtual Task <bool> CloseModalViewController(IMvxViewModel toClose, MvxModalPresentationAttribute attribute)
        {
            if (ModalViewControllers == null || !ModalViewControllers.Any())
            {
                return(Task.FromResult(false));
            }

            // check for plain modals
            var modalToClose = ModalViewControllers.FirstOrDefault(v => v is IMvxIosView && v.GetIMvxIosView().ViewModel == toClose);

            if (modalToClose != null)
            {
                return(CloseModalViewController(modalToClose, attribute));
            }

            // check for modal navigation stacks
            UIViewController controllerToClose = null;

            foreach (var vc in ModalViewControllers.Where(v => v is UINavigationController))
            {
                var root = ((UINavigationController)vc).ViewControllers.FirstOrDefault();
                if (root != null && root.GetIMvxIosView().ViewModel == toClose)
                {
                    controllerToClose = vc;
                    break;
                }
            }
            if (controllerToClose != null)
            {
                return(CloseModalViewController(controllerToClose, attribute));
            }

            return(Task.FromResult(false));
        }
Ejemplo n.º 8
0
 public virtual void CloseModalViewControllers()
 {
     while (ModalViewControllers.Any())
     {
         CloseModalViewController(ModalViewControllers.LastOrDefault(), new MvxModalPresentationAttribute());
     }
 }
Ejemplo n.º 9
0
 protected async Task <bool> CloseModalViewControllers()
 {
     while (ModalViewControllers.Any())
     {
         if (!(await CloseModalViewController(ModalViewControllers.LastOrDefault())))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 10
0
 public virtual async Task <bool> CloseModalViewControllers()
 {
     while (ModalViewControllers.Any())
     {
         if (!(await CloseModalViewController(ModalViewControllers.LastOrDefault(), new MvxModalPresentationAttribute())))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 11
0
        protected override Task <bool> ShowChildViewController(
            UIViewController viewController,
            MvxChildPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            if (viewController is IMvxSplitViewController)
            {
                throw new MvxException("A SplitViewController cannot be presented as a child. Consider using Root instead");
            }

            if (ModalViewControllers.Any())
            {
                if (ModalViewControllers.LastOrDefault() is UINavigationController modalNavController)
                {
                    PushViewControllerIntoStack(modalNavController, viewController, attribute);

                    return(Task.FromResult(true));
                }
                throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is currently a plain modal view presented!");
            }

            if (TabBarViewController != null)
            {
                if (request.PresentationValues != null &&
                    request.PresentationValues.ContainsKey(Presenter.NavigationModeKey))
                {
                    if (request.PresentationValues[Presenter.NavigationModeKey] == Presenter.ReplaceKey)
                    {
                        if (TabBarViewController is MainView mv)
                        {
                            mv.ReplaceTopChildViewModel(viewController);
                            return(Task.FromResult(true));
                        }
                    }
                }
                else
                {
                    return(Task.FromResult(TabBarViewController.ShowChildView(viewController)));
                }
            }

            if (MasterNavigationController != null)
            {
                PushViewControllerIntoStack(MasterNavigationController, viewController, attribute);
                return(Task.FromResult(true));
            }

            throw new MvxException($"Trying to show View type: {viewController.GetType().Name} as child, but there is no current stack!");
        }
Ejemplo n.º 12
0
        protected virtual bool CloseModalViewController(IMvxViewModel toClose)
        {
            if (ModalViewControllers == null || !ModalViewControllers.Any())
            {
                return(false);
            }

            // check for plain modals
            var modalToClose = ModalViewControllers.FirstOrDefault(v => v is IMvxIosView && v.GetIMvxIosView().ViewModel == toClose);

            if (modalToClose != null)
            {
                CloseModalViewController(modalToClose);
                return(true);
            }

            // check for modal navigation stacks
            UIViewController controllerToClose = null;

            foreach (var vc in ModalViewControllers.Where(v => v is UINavigationController))
            {
                var root = ((UINavigationController)vc).ViewControllers.FirstOrDefault();
                if (root != null && root.GetIMvxIosView().ViewModel == toClose)
                {
                    controllerToClose = root;
                    break;
                }
            }
            if (controllerToClose != null)
            {
                CloseModalViewController(controllerToClose);
                return(true);
            }

            return(false);
        }