protected override void ShowView(IModalView view, bool isDialog, IDataContext context) { var parentController = (UIViewController)ViewModel .GetIocContainer(true) .Get <INavigationService>() .CurrentContent; var toShow = view.GetUnderlyingView <UIViewController>(); bool animated; if (context.TryGetData(NavigationConstants.UseAnimations, out animated)) { ViewModel.Settings.State.AddOrUpdate(NavigationConstants.UseAnimations, animated); } else { animated = UseAnimations; } if (view is IModalNavSupportView) { var nav = new MvvmNavigationController(); nav.PushViewController(toShow, animated); toShow = nav; BindProvider(nav); } parentController.PresentViewController(toShow, animated, NodoAction); toShow.TryRaiseAttachedEvent(AttachedMembers.Object.Parent); }
/// <summary> /// Tries to restore view controller. /// </summary> public virtual UIViewController GetViewController(string[] restorationIdentifierComponents, NSCoder coder, IDataContext context = null) { string id = restorationIdentifierComponents.LastOrDefault(); Type type = PlatformExtensions.GetTypeFromRestorationIdentifier(id); if (type == null) { return(null); } 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 = id; 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).GetUnderlyingView(); } 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) { NavigationController.PushViewController(viewController, true); } RaiseNavigated(viewController, NavigationMode.New, parameter); return(true); }
/// <summary> /// Shows the view in the specified mode. /// </summary> protected override void ShowView(IModalView view, bool isDialog, IDataContext context) { var parentController = (UIViewController)ViewModel .GetIocContainer(true) .Get <INavigationService>() .CurrentContent; UIViewController toShow; if (view is IModalNavSupportView) { var nav = new MvvmNavigationController(); nav.PushViewController((UIViewController)view, UseAnimations); toShow = nav; BindProvider(nav); } else { toShow = (UIViewController)view; } parentController.PresentViewController(toShow, UseAnimations, NodoAction); BindingExtensions.AttachedParentMember.Raise(toShow, EventArgs.Empty); }
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)ToolkitServiceProvider.Get(type); } } controller.RestorationIdentifier = restorationIdentifier; return(controller); }
public virtual bool Navigate(IViewMappingItem source, string 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.Get <IViewManager>().GetViewAsync(source, dataContext).Result; } 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); }