public void SetLifetimeScope(ILifetimeScope scope) { this._scope = scope; this._navigator = scope.Resolve <IStackNavigator>(); this.InitializeMainPage(); }
/// <summary> /// Creates a new instance of <see cref="SectionStackNavigator"/>. /// </summary> /// <param name="inner">The decorated stack navigator.</param> /// <param name="name">The name of this section.</param> /// <param name="isModal">Flag indicating whether this section is a modal.</param> /// <param name="priority">The priority of the section.</param> /// <param name="closeModalTransitionInfo">The default transition info for the close modal operation. This is only relevant for modals.</param> public SectionStackNavigator(IStackNavigator inner, string name, bool isModal, int priority, SectionsTransitionInfo closeModalTransitionInfo = null) { _inner = inner; Name = name; IsModal = isModal; Priority = priority; CloseModalTransitionInfo = closeModalTransitionInfo; _inner.StateChanged += OnInnerStateChanged; }
/// <summary> /// Processes a <see cref="StackNavigatorRequest"/> based on its <see cref="StackNavigatorRequestType"/>. /// </summary> /// <param name="stackNavigator">The stack navigator.</param> /// <param name="ct">The cancellation token.</param> /// <param name="request">The request to process.</param> public static Task ProcessRequest(this IStackNavigator stackNavigator, CancellationToken ct, StackNavigatorRequest request) { switch (request.RequestType) { case StackNavigatorRequestType.NavigateForward: return(stackNavigator.Navigate(ct, request)); case StackNavigatorRequestType.NavigateBack: return(stackNavigator.NavigateBack(ct)); case StackNavigatorRequestType.Clear: return(stackNavigator.Clear(ct)); case StackNavigatorRequestType.RemoveEntry: return(stackNavigator.RemoveEntries(ct, request.EntryIndexesToRemove)); default: throw new NotSupportedException($"The request type '{request.RequestType}' is not supported."); } }
/// <summary> /// Tries to navigate back to the ViewModel matching <typeparamref name="TPageViewModel"/>. /// </summary> /// <remarks> /// If no previous entry matches <typeparamref name="TPageViewModel"/>, nothing happens. /// </remarks> /// <typeparam name="TPageViewModel">The ViewModel type.</typeparam> /// <param name="navigator">The stack navigator.</param> /// <param name="ct">The cancellation token.</param> /// <returns>True if the navigate back happened. False otherwise.</returns> public static async Task <bool> TryNavigateBackTo <TPageViewModel>(this IStackNavigator navigator, CancellationToken ct) { var logger = typeof(StackNavigatorExtensions).Log(); // Retrieve the current stack and its size var stack = navigator.State.Stack; var count = stack.Count; // Retrieve the instance of the target ViewModel var targetEntry = stack.FirstOrDefault(entry => entry.ViewModel.GetType() == typeof(TPageViewModel)); if (targetEntry != null) { // Retrieve the index of the target viewModel var startIndex = stack.ToList().IndexOf(targetEntry); // Count how many items we should delete between the target viewModel and the current page viewmodel var itemsToDelete = count - 1 - startIndex - 1; if (itemsToDelete > 0) { var indexesToRemove = Enumerable.Range(startIndex + 1, itemsToDelete); await navigator.RemoveEntries(ct, indexesToRemove); } // Navigate back to the target view model await navigator.NavigateBack(ct); return(true); } else { if (logger.IsEnabled(LogLevel.Warning)) { logger.LogWarning($"Can't navigate back to '{typeof(TPageViewModel).Name}' because it's not in the navigation stack."); } return(false); } }
/// <summary> /// Gets whether the navigator from a <see cref="SectionsNavigatorRequestType.ReportSectionStateChanged"/> request is active. /// </summary> /// <param name="sectionsNavigatorState"></param> /// <param name="stackNavigator">The stack navigator that caused the <see cref="SectionsNavigatorRequestType.ReportSectionStateChanged"/> request if it's active. Null otherwhise.</param> /// <returns>Returns true when the <see cref="IStackNavigator"/> that caused the current <see cref="SectionsNavigatorRequestType.ReportSectionStateChanged"/> is currently active. False otherwise.</returns> public static bool IsStackNavigatorFromSectionsRequestActive(this SectionsNavigatorState sectionsNavigatorState, out IStackNavigator stackNavigator) { var sectionsNavigatorRequest = sectionsNavigatorState.LastRequest; var modalName = sectionsNavigatorRequest.ModalName; if (modalName != null) { stackNavigator = sectionsNavigatorState.Modals.FirstOrDefault(m => m.Name == modalName); if (stackNavigator == null) { return(false); } else { return(stackNavigator == sectionsNavigatorState.ActiveModal); } } else { var sectionName = sectionsNavigatorRequest.SectionName; stackNavigator = sectionsNavigatorState.Sections[sectionName]; // Don't consider the section active if a Modal is active. return(stackNavigator == sectionsNavigatorState.ActiveSection && sectionsNavigatorState.ActiveModal == null); } }
/// <summary> /// Gets the ViewModel instance of the last item of this <see cref="IStackNavigator"/>'s stack. /// </summary> /// <param name="navigator">The stack navigator.</param> public static INavigableViewModel GetActiveViewModel(this IStackNavigator navigator) { return(navigator.State.Stack.LastOrDefault()?.ViewModel); }
/// <summary> /// Removes the previous ViewModel from this <see cref="IStackNavigator"/>' stack. /// </summary> /// <param name="navigator">The stack navigator.</param> /// <param name="ct">The cancellation token.</param> public static async Task RemovePrevious(this IStackNavigator navigator, CancellationToken ct) { await navigator.RemoveEntries(ct, new[] { navigator.State.Stack.Count - 2 }); }
/// <summary> /// Navigates forward. /// </summary> /// <typeparam name="TViewModel">The type of the view model.</typeparam> /// <param name="navigator">The stack navigator.</param> /// <param name="ct">The cancellation token.</param> /// <param name="viewModelProvider">The method to invoke to instanciate the ViewModel.</param> /// <param name="suppressTransition">Whether to suppress the navigation transition.</param> /// <returns>The ViewModel instance of the active page after the navigation operation.</returns> public static async Task <TViewModel> Navigate <TViewModel>(this IStackNavigator navigator, CancellationToken ct, Func <TViewModel> viewModelProvider, bool suppressTransition = false) where TViewModel : INavigableViewModel { return((TViewModel)await navigator.Navigate(ct, StackNavigatorRequest.GetNavigateRequest(viewModelProvider, suppressTransition))); }
/// <summary> /// Gets whether the navigator can navigate back. /// </summary> /// <param name="stackNavigator">The stack navigator.</param> public static bool CanNavigateBack(this IStackNavigator stackNavigator) { // Can't back if you only have 1 item in the stack because the stack contains the current item. return(stackNavigator.State.Stack.Count >= 2); }
public MobileViewModelBase(IStackNavigator navigator) { this.Navigator = navigator; this._navigateCommand = new Command <string>(this.ExecuteNavigateCommand, this.CanExecuteNavigateCommand); }
/// <summary> /// Gets an observable sequence that produces values whenever <see cref="IStackNavigator.StateChanged"/> is raised, pushing only the <see cref="StackNavigatorEventArgs.CurrentState"/> value. /// </summary> /// <param name="navigator">The stack navigator.</param> /// <returns>An observable sequence of <see cref="StackNavigatorState"/>.</returns> public static IObservable <StackNavigatorState> ObserveCurrentState(this IStackNavigator navigator) { return(navigator .ObserveStateChanged() .Select(pattern => pattern.EventArgs.CurrentState)); }
/// <summary> /// Gets an observable sequence that produces values whenever <see cref="IStackNavigator.StateChanged"/> is raised. /// </summary> /// <param name="navigator">The stack navigator.</param> /// <returns>An observable sequence of <see cref="EventPattern{SectionsNavigatorEventArgs}"/>.</returns> public static IObservable <EventPattern <StackNavigatorEventArgs> > ObserveStateChanged(this IStackNavigator navigator) { return(Observable .FromEventPattern <StackNavigatorStateChangedEventHandler, StackNavigatorEventArgs>( handler => navigator.StateChanged += handler, handler => navigator.StateChanged -= handler )); }
public LoginPageViewModel(IStackNavigator navigator) : base(navigator) { }
public NextPageViewModel(IStackNavigator navigator) : base(navigator) { }