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)); }
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 Task <bool> ShowModalViewController( UIViewController viewController, MvxModalPresentationAttribute attribute, MvxViewModelRequest request) { // Content size should be set to a target view controller, not the navigation one if (attribute.PreferredContentSize != default(CGSize)) { viewController.PreferredContentSize = attribute.PreferredContentSize; } // setup modal based on attribute if (attribute.WrapInNavigationController) { viewController = CreateNavigationController(viewController); } viewController.ModalPresentationStyle = attribute.ModalPresentationStyle; viewController.ModalTransitionStyle = attribute.ModalTransitionStyle; // Check if there is a modal already presented first. Otherwise use the window root var modalHost = ModalViewControllers.LastOrDefault() ?? _window.RootViewController; modalHost.PresentViewController( viewController, attribute.Animated, null); ModalViewControllers.Add(viewController); return(Task.FromResult(true)); }
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 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}"); }
public virtual void CloseModalViewControllers() { while (ModalViewControllers.Any()) { CloseModalViewController(ModalViewControllers.LastOrDefault(), new MvxModalPresentationAttribute()); } }
protected virtual bool CloseModalViewController(IMvxViewModel toClose) { // check if there is a modal stack presented if (ModalViewControllers.LastOrDefault() is UINavigationController modalNavController) { if (TryCloseViewControllerInsideStack(modalNavController, toClose)) { // First() is the RootViewController of the stack. If it is being closed, then remove the nav stack if (modalNavController.ViewControllers.First().GetIMvxIosView().ViewModel == toClose) { CloseModalViewController(modalNavController); } return(true); } } else { // close any plain modal presented var last = ModalViewControllers.Last(); if (last.GetIMvxIosView().ViewModel == toClose) { CloseModalViewController(last); return(true); } } return(false); }
protected virtual void ShowModalViewController( UIViewController viewController, MvxModalPresentationAttribute attribute, MvxViewModelRequest request) { // setup modal based on attribute if (attribute.WrapInNavigationController) { viewController = CreateNavigationController(viewController); } viewController.ModalPresentationStyle = attribute.ModalPresentationStyle; viewController.ModalTransitionStyle = attribute.ModalTransitionStyle; if (attribute.PreferredContentSize != default(CGSize)) { viewController.PreferredContentSize = attribute.PreferredContentSize; } // Check if there is a modal already presented first. Otherwise use the window root var modalHost = ModalViewControllers.LastOrDefault() ?? _window.RootViewController; modalHost.PresentViewController( viewController, attribute.Animated, null); ModalViewControllers.Add(viewController); }
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> 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 void CleanupModalViewControllers() { while (ModalViewControllers.Any()) { CloseModalViewController(ModalViewControllers.LastOrDefault()); } }
private void showModalDialogViewController(UIViewController viewController, MvxBasePresentationAttribute attribute, MvxViewModelRequest request) { viewController.ModalPresentationStyle = UIModalPresentationStyle.Custom; viewController.TransitioningDelegate = modalTransitionDelegate; getCurrentControllerForPresenting(MasterNavigationController).PresentViewController(viewController, true, null); ModalViewControllers.Add(viewController); }
protected virtual void ShowModalCardViewController(UIViewController viewController, MvxBasePresentationAttribute attribute, MvxViewModelRequest request) { viewController.ModalPresentationStyle = UIModalPresentationStyle.Custom; viewController.TransitioningDelegate = FromBottomTransitionDelegate; MasterNavigationController.PresentViewController(viewController, true, null); ModalViewControllers.Add(viewController); FromBottomTransitionDelegate.WireToViewController(viewController, () => ModalViewControllers.Remove(viewController)); }
public virtual async Task <bool> CloseModalViewControllers() { while (ModalViewControllers.Any()) { if (!(await CloseModalViewController(ModalViewControllers.LastOrDefault(), new MvxModalPresentationAttribute()))) { return(false); } } return(true); }
private void showModalDialogViewController(Type viewType, MvxBasePresentationAttribute attribute, MvxViewModelRequest request) { var viewController = (UIViewController)this.CreateViewControllerFor(request); viewController.ModalPresentationStyle = UIModalPresentationStyle.Custom; viewController.TransitioningDelegate = modalTransitionDelegate; TopViewController.PresentViewController(viewController, true, null); ModalViewControllers.Add(viewController); }
protected async Task <bool> CloseModalViewControllers() { while (ModalViewControllers.Any()) { if (!(await CloseModalViewController(ModalViewControllers.LastOrDefault()))) { return(false); } } return(true); }
private void showModalCardViewController(Type viewType, MvxBasePresentationAttribute attribute, MvxViewModelRequest request) { var viewController = (UIViewController)this.CreateViewControllerFor(request); var transitionDelegate = new FromBottomTransitionDelegate( () => ModalViewControllers.Remove(viewController) ); viewController.ModalPresentationStyle = UIModalPresentationStyle.Custom; viewController.TransitioningDelegate = transitionDelegate; TopViewController.PresentViewController(viewController, true, null); ModalViewControllers.Add(viewController); }
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!"); }
private void showModalCardViewController(UIViewController viewController, MvxBasePresentationAttribute attribute, MvxViewModelRequest request) { var transitionDelegate = new FromBottomTransitionDelegate( () => ModalViewControllers.Remove(viewController) ); viewController.ModalPresentationStyle = UIModalPresentationStyle.Custom; viewController.TransitioningDelegate = transitionDelegate; getCurrentControllerForPresenting(MasterNavigationController).PresentViewController(viewController, true, null); ModalViewControllers.Add(viewController); transitionDelegate.WireToViewController(viewController); }
protected virtual void CloseModalViewController(UIViewController modalController) { if (modalController == null) { return; } if (modalController is UINavigationController modalNavController) { foreach (var item in modalNavController.ViewControllers) { item.DidMoveToParentViewController(null); } } modalController.DismissViewController(true, null); ModalViewControllers.Remove(modalController); }
public virtual void CloseModalViewController(UIViewController viewController, MvxModalPresentationAttribute attribute) { if (viewController == null) { return; } if (viewController is UINavigationController modalNavController) { foreach (var item in modalNavController.ViewControllers) { item.DidMoveToParentViewController(null); } } viewController.DismissViewController(attribute.Animated, null); ModalViewControllers.Remove(viewController); }
protected virtual void CloseModalViewController(UIViewController viewController) { if (viewController == null) { return; } if (viewController is UINavigationController navController) { foreach (var view in navController.ViewControllers) { view.DidMoveToParentViewController(null); } } viewController.DismissViewController(true, null); ModalViewControllers.Remove(viewController); }
protected virtual Task <bool> CloseModalViewController(UIViewController viewController) { if (viewController == null) { return(Task.FromResult(true)); } if (viewController is UINavigationController navController) { foreach (var view in navController.ViewControllers) { view.DidMoveToParentViewController(null); } } viewController.DismissViewController(true, null); ModalViewControllers.Remove(viewController); return(Task.FromResult(true)); }
public virtual async Task <bool> CloseModalViewController(UIViewController viewController, MvxModalPresentationAttribute attribute) { if (viewController == null) { return(true); } if (viewController is UINavigationController modalNavController) { foreach (var item in modalNavController.ViewControllers) { item.DidMoveToParentViewController(null); } } await viewController.DismissViewControllerAsync(attribute.Animated); ModalViewControllers.Remove(viewController); return(true); }
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); }
public virtual void NativeModalViewControllerDisappearedOnItsOwn() { CloseModalViewController(ModalViewControllers.Last()); }
public virtual void CloseTopModalViewController() { CloseModalViewController(ModalViewControllers?.Last()); }
public override void NativeModalViewControllerDisappearedOnItsOwn() { CloseModalViewController(ModalViewControllers.Last()); }
public virtual ValueTask <bool> CloseTopModalViewController() { return(CloseModalViewController(ModalViewControllers?.Last())); }