public override UIViewController PopViewController(bool animated) { var c = ViewControllers.LastOrDefault(); Router.BackAsync(); return(c); }
public override UIViewController PopViewController(bool animated) { if (ViewControllers.Length <= 2) { var vc = ViewControllers.LastOrDefault(); DismissViewController(animated, () => base.PopViewController(false)); return(vc); } return(base.PopViewController(animated)); }
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(); }