| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="NavigationClient.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Threading; |
| | | 9 | | using System.Threading.Tasks; |
| | | 10 | | using Microsoft.Extensions.DependencyInjection; |
| | | 11 | | using MyNet.UI.Navigation.Models; |
| | | 12 | | |
| | | 13 | | namespace MyNet.UI.Navigation; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Default high-level navigation client. |
| | | 17 | | /// </summary> |
| | | 18 | | public sealed class NavigationClient(INavigationService navigationService, IServiceProvider serviceProvider) : INavigati |
| | | 19 | | { |
| | | 20 | | /// <inheritdoc /> |
| | | 21 | | public event EventHandler<NavigationStateChangedEventArgs>? StateChanged |
| | | 22 | | { |
| | 3 | 23 | | add => navigationService.StateChanged += value; |
| | 0 | 24 | | remove => navigationService.StateChanged -= value; |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | 9 | 28 | | public NavigationContext? CurrentContext => navigationService.CurrentContext; |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | 6 | 31 | | public bool CanGoBack => navigationService.CanGoBack; |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | 6 | 34 | | public bool CanGoForward => navigationService.CanGoForward; |
| | | 35 | | |
| | | 36 | | /// <inheritdoc /> |
| | | 37 | | public INavigationRequestBuilder To<TPage>() |
| | | 38 | | where TPage : class, INavigationPage |
| | 12 | 39 | | => new NavigationRequestBuilder( |
| | 12 | 40 | | () => ActivatorUtilities.GetServiceOrCreateInstance<TPage>(serviceProvider), |
| | 12 | 41 | | navigationService); |
| | | 42 | | |
| | | 43 | | /// <inheritdoc /> |
| | | 44 | | public Task<NavigationResult> NavigateToAsync<TPage>(object? parameters = null, CancellationToken cancellationToken |
| | | 45 | | where TPage : class, INavigationPage |
| | 9 | 46 | | => To<TPage>().With(parameters).GoAsync(cancellationToken); |
| | | 47 | | |
| | | 48 | | /// <inheritdoc /> |
| | | 49 | | public Task<NavigationResult> GoBackAsync(CancellationToken cancellationToken = default) |
| | 3 | 50 | | => navigationService.GoBackAsync(cancellationToken); |
| | | 51 | | |
| | | 52 | | /// <inheritdoc /> |
| | | 53 | | public Task<NavigationResult> GoForwardAsync(CancellationToken cancellationToken = default) |
| | 3 | 54 | | => navigationService.GoForwardAsync(cancellationToken); |
| | | 55 | | |
| | | 56 | | /// <inheritdoc /> |
| | 3 | 57 | | public Task ResetAsync() => navigationService.ResetAsync(); |
| | | 58 | | } |
| | | 59 | | |