public static bool DisplayViewController(this UINavigationController navController, UIViewController viewController, bool animate) { // Crashed with error in Linq, //UIViewController found = navController.ViewControllers.First(v => v == viewController); bool found = false; foreach (var vc in navController.ViewControllers) { if (vc == viewController) { found = true; break; } } if (found) { navController.PopToViewController(viewController, animate); } else { navController.PushViewController(viewController, animate); } return(true); }
public void NavigateToModal <TViewModel>() { var viewModel = Locator.Resolve <TViewModel>(); var viewController = GetViewController(viewModel); _navigationController.PopToViewController(viewController, false); }
public override void ChangePresentation(MvxPresentationHint hint) { var closeHint = hint as MvxClosePresentationHint; if (closeHint != null) { if (_currentModal != null) { ((UIViewController)_currentModal).DismissViewController(true, null); return; } for (int i = _generalNavigationController.ViewControllers.Length - 1; i >= 1; i--) { var vc = _generalNavigationController.ViewControllers[i]; var touchView = vc as IMvxTouchView; if (touchView != null && touchView.ViewModel == closeHint.ViewModelToClose) { _generalNavigationController.PopToViewController(_generalNavigationController.ViewControllers[i - 1], true); return; } } //If it didnt trigger above it's because it was probably the root. _generalNavigationController.PopToRootViewController(true); } }
/// <summary> /// Navigate to a view controller instance. /// </summary> /// <param name="viewController"></param> /// <param name="animated"></param> private void Navigate(UIViewController viewController, bool animated = false) { if (Object.ReferenceEquals(navigationContext.TopViewController, viewController)) { return; } if (navigationContext.ViewControllers != null) { foreach (var stackViewController in navigationContext.ViewControllers) { if (Object.ReferenceEquals(stackViewController, viewController)) { navigationContext.PopToViewController(viewController, animated); return; } } } navigationContext.PushViewController(viewController, animated); }
private bool PopToViewController(UINavigationController navigationController, Type type, bool animated) { foreach (var viewController in navigationController.ViewControllers) { if (viewController.GetType() == type) { navigationController.PopToViewController(viewController, animated); return(true); } } return(false); }
public void NavigateToMaster(UIViewController vc) { // first time through! if (_splitViewController == null && _masterNavigationController == null) { Init(vc); } else { bool contains = _masterNavigationController.ViewControllers.Contains(vc); if (contains) { _masterNavigationController.PopToViewController(vc, true); } else { _masterNavigationController.PushViewController(vc, true); } } }
public override void Execute(CallbackActionWaiter callbackActionWaiter, bool animated) { UINavigationController navigationController = (UINavigationController)HostStack.Host; List <UIViewController> vcs = navigationController.ViewControllers.ToList(); if (CountToPop == 1) { UIViewController poppedViewController = vcs[vcs.Count - 1]; callbackActionWaiter.Add(() => poppedViewController.SafeDispose()); navigationController.PopViewController(animated); } else { int popToIndex = vcs.Count - 1 - CountToPop; navigationController.PopToViewController(vcs[popToIndex], animated); callbackActionWaiter.Add(() => { for (int i = popToIndex + 1; i < vcs.Count; ++i) { vcs[i].SafeDispose(); } }); } }
public void PopToLayer(iLayer layer) { var display = NavigationController.ViewControllers.OfType <IMXView>().First(vc => layer.Equals(vc.GetModel())); NavigationController.PopToViewController(display as UIViewController, true); }
public override void PushViewController(UIViewController viewController, bool animated) { if (ViewControllers.Length <= 0) { // NOTE: pushViewController is called by init(rootViewController: UIViewController) // so we must perform the normal super method in this case. base.PushViewController(viewController, animated: true); return; } UINavigationController presentingViewController = null; if (PresentingViewController is UINavigationController) { presentingViewController = PresentingViewController as UINavigationController; } else if (PresentingViewController is UITabBarController) { presentingViewController = ((UITabBarController)PresentingViewController).SelectedViewController as UINavigationController; } if (presentingViewController == null) { PresentViewController(viewController, animated, null); System.Diagnostics.Debug.WriteLine("SideMenu Warning: cannot push a ViewController from a ViewController without a NavigationController. It will be presented it instead."); return; } // to avoid overlapping dismiss & pop/push calls, create a transaction block where the menu // is dismissed after showing the appropriate screen CATransaction.Begin(); CATransaction.CompletionBlock = () => { this.DismissViewController(true, null); this.VisibleViewController?.ViewWillAppear(false); // Hack: force selection to get cleared on UITableViewControllers when reappearing using custom transitions }; UIView.Animate(SideMenuManager.AnimationDismissDuration, animation: () => SideMenuManager.SideMenuTransition.HideMenuStart()); if (SideMenuManager.AllowPopIfPossible) { foreach (var subViewController in presentingViewController.ViewControllers) { //TODO: Review this if (subViewController.GetType() == viewController.GetType()) // if subViewController.dynamicType == viewController.dynamicType { { presentingViewController.PopToViewController(subViewController, animated: animated); CATransaction.Commit(); return; } } } if (!SideMenuManager.AllowPushOfSameClassTwice) { //TODO: Review this if (presentingViewController.ViewControllers[presentingViewController.ViewControllers.Length - 1].GetType() == viewController.GetType()) //if presentingViewController.viewControllers.last?.dynamicType == viewController.dynamicType { { CATransaction.Commit(); return; } } presentingViewController.PushViewController(viewController, animated: animated); CATransaction.Commit(); }
public override void PushViewController(UIViewController viewController, bool animated) { if (ViewControllers.Length <= 0) { // NOTE: pushViewController is called by init(rootViewController: UIViewController) // so we must perform the normal super method in this case. base.PushViewController(viewController, animated: true); return; } UINavigationController presentingViewController = null; if (PresentingViewController is UINavigationController) { presentingViewController = PresentingViewController as UINavigationController; } else if (PresentingViewController is UITabBarController) { presentingViewController = ((UITabBarController)PresentingViewController).SelectedViewController as UINavigationController; } if (presentingViewController == null) { PresentViewController(viewController, animated, null); System.Diagnostics.Debug.WriteLine("SideMenu Warning: cannot push a ViewController from a ViewController without a NavigationController. It will be presented it instead."); return; } // to avoid overlapping dismiss & pop/push calls, create a transaction block where the menu // is dismissed after showing the appropriate screen CATransaction.Begin(); CATransaction.CompletionBlock = () => { if (SideMenuManager.MenuPushStyle != SideMenuManager.MenuPushStyleType.NoNavigation) { this.DismissViewController(true, null); } this.VisibleViewController?.ViewWillAppear(false); // Hack: force selection to get cleared on UITableViewControllers when reappearing using custom transitions }; UIView.Animate(SideMenuManager.AnimationDismissDuration, animation: () => SideMenuManager.SideMenuTransition.HideMenuStart()); if (!SideMenuManager.AllowPushOfSameClassTwice) { //TODO: Review this var lastView = ViewControllers.LastOrDefault(); if (lastView != null && lastView.GetType() == viewController.GetType()) //if presentingViewController.viewControllers.last?.dynamicType == viewController.dynamicType { { CATransaction.Commit(); return; } } switch (SideMenuManager.MenuPushStyle) { case SideMenuManager.MenuPushStyleType.SubMenu: case SideMenuManager.MenuPushStyleType.DefaultBehavior: break; case SideMenuManager.MenuPushStyleType.PopWhenPossible: foreach (var subViewController in presentingViewController.ViewControllers.Reverse()) { if (subViewController.GetType() == viewController.GetType()) { presentingViewController.PopToViewController(subViewController, animated: animated); CATransaction.Commit(); return; } } break; case SideMenuManager.MenuPushStyleType.Preserve: case SideMenuManager.MenuPushStyleType.PreserveAndHideBackButton: var viewControllers = presentingViewController.ViewControllers; var preservedViewController = viewControllers.Where(x => x.GetType() == viewController.GetType()).LastOrDefault(); if (preservedViewController != null) { if (SideMenuManager.MenuPushStyle == SideMenuManager.MenuPushStyleType.PreserveAndHideBackButton) { preservedViewController.NavigationItem.SetHidesBackButton(true, false); } viewControllers.Append(preservedViewController); presentingViewController.SetViewControllers(viewControllers, animated: animated); CATransaction.Commit(); return; } if (SideMenuManager.MenuPushStyle == SideMenuManager.MenuPushStyleType.PreserveAndHideBackButton) { viewController.NavigationItem.SetHidesBackButton(true, false); } break; case SideMenuManager.MenuPushStyleType.Replace: case SideMenuManager.MenuPushStyleType.NoNavigation: if (SideMenuManager.MenuPushStyle != SideMenuManager.MenuPushStyleType.NoNavigation) { viewController.NavigationItem.LeftBarButtonItem = SideMenuManager.LeftNavigationController.NavigationItem.LeftBarButtonItem; viewController.NavigationItem.RightBarButtonItem = SideMenuManager.LeftNavigationController.NavigationItem.RightBarButtonItem; } else { viewController.NavigationItem.SetHidesBackButton(true, false); } UIViewController[] viewctrl = { viewController }; presentingViewController.SetViewControllers(viewctrl, true); CATransaction.Commit(); return; default: break; } presentingViewController.PushViewController(viewController, animated: animated); CATransaction.Commit(); }