protected virtual UIViewController GetViewControllerInternal([NotNull] string restorationIdentifier, [NotNull] Type type, [NotNull] NSCoder coder, [NotNull] IDataContext context) { UIViewController controller = null; Func<Type, NSCoder, IDataContext, UIViewController> factory = ViewControllerFactory; if (factory != null) controller = factory(type, coder, context); if (controller == null) { if (type == typeof(MvvmNavigationController)) controller = new MvvmNavigationController(); else controller = (UIViewController)ServiceProvider.IocContainer.Get(type); } controller.RestorationIdentifier = restorationIdentifier; return controller; }
protected virtual UINavigationController GetNavigationController(UIWindow window, UIViewController rootController, out bool isRootNavigated) { isRootNavigated = true; if (_getOrCreateController == null) { var controller = window.RootViewController as UINavigationController; if (controller == null) { controller = new MvvmNavigationController(rootController); window.RootViewController = controller; return controller; } isRootNavigated = false; return controller; } return _getOrCreateController(window, rootController); }
/// <summary> /// Displays the content located at the specified <see cref="IViewMappingItem" />. /// </summary> /// <param name="source"> /// The <c>IViewPageMappingItem</c> of the content to display. /// </param> /// <param name="parameter"> /// A <see cref="T:System.Object" /> that contains data to be used for processing during /// navigation. /// </param> /// <param name="dataContext"> /// The specified <see cref="IDataContext" />. /// </param> /// <returns> /// <c>true</c> if the content was successfully displayed; otherwise, <c>false</c>. /// </returns> public virtual bool Navigate(IViewMappingItem source, object parameter, IDataContext dataContext) { Should.NotBeNull(source, "source"); EnsureInitialized(); if (!RaiseNavigating(new NavigatingCancelEventArgs(source, NavigationMode.New, parameter))) return false; if (dataContext == null) dataContext = DataContext.Empty; IViewModel viewModel = dataContext.GetData(NavigationConstants.ViewModel); UIViewController viewController; if (viewModel == null) viewController = (UIViewController)ServiceProvider.IocContainer.Get(source.ViewType); else viewController = (UIViewController)ViewManager.GetOrCreateView(viewModel, null, dataContext); viewController.SetNavigationParameter(parameter); bool shouldNavigate = true; if (_window != null) { var controller = _window.RootViewController as UINavigationController; if (controller == null) { shouldNavigate = false; controller = new MvvmNavigationController(viewController); _window.RootViewController = controller; } InitializeNavigationController(controller); } if (shouldNavigate) { bool animated; if (dataContext.TryGetData(NavigationConstants.UseAnimations, out animated)) { if (viewModel != null) viewModel.Settings.State.AddOrUpdate(NavigationConstants.UseAnimations, animated); } else animated = UseAnimations; if (!ClearNavigationStackIfNeed(viewController, dataContext, animated)) NavigationController.PushViewController(viewController, animated); } var view = viewController as IViewControllerView; if (view == null || view.Mediator.IsAppeared) RaiseNavigated(viewController, NavigationMode.New, parameter); else view.Mediator.ViewDidAppearHandler += OnViewDidAppearHandlerNew; return true; }