protected void CleanupModalViewControllers() { while (ModalViewControllers.Any()) { CloseModalViewController(ModalViewControllers.LastOrDefault()); } }
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); }
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)); }
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 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!"); }
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)); }
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)); }
public virtual void CloseModalViewControllers() { while (ModalViewControllers.Any()) { CloseModalViewController(ModalViewControllers.LastOrDefault(), new MvxModalPresentationAttribute()); } }
protected async Task <bool> CloseModalViewControllers() { while (ModalViewControllers.Any()) { if (!(await CloseModalViewController(ModalViewControllers.LastOrDefault()))) { return(false); } } return(true); }
public virtual async Task <bool> CloseModalViewControllers() { while (ModalViewControllers.Any()) { if (!(await CloseModalViewController(ModalViewControllers.LastOrDefault(), new MvxModalPresentationAttribute()))) { return(false); } } return(true); }
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!"); }
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); }