예제 #1
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);
        }
예제 #2
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));
        }
예제 #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));
        }
예제 #4
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));
        }
예제 #5
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);
        }