Beispiel #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);
        }
Beispiel #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));
        }
        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}");
        }
        protected virtual void Close(IMvxViewModel toClose)
        {
            // check if toClose is a modal ViewController
            if (Window.RootViewController.PresentedViewController != null)
            {
                UIViewController viewController;
                // the presented ViewController might be a NavigationController as well
                var navigationController = Window.RootViewController.PresentedViewController as UINavigationController;
                viewController = navigationController != null
                                                                        ? navigationController.TopViewController
                                                                        : Window.RootViewController.PresentedViewController;

                var mvxView = viewController.GetIMvxIosView();

                if (mvxView.ViewModel == toClose)
                {
                    Window.RootViewController.DismissViewController(true, null);
                    return;
                }
            }

            // check if ViewModel is shown inside TabBarViewController
            // if so, the TabBarViewController takes care of it
            if (TabBarViewController != null)
            {
                TabBarViewController.CloseChildViewModel(toClose);
                return;
            }

            // close ViewModel shown inside NavigationController
            if (NavigationController.TopViewController.GetIMvxIosView().ViewModel == toClose)
            {
                NavigationController.PopViewController(true);
            }
            else
            {
                ClosePreviousController(toClose);
            }
        }