diff --git a/src/Maui/Prism.Maui/Navigation/Builder/INavigationBuilder.cs b/src/Maui/Prism.Maui/Navigation/Builder/INavigationBuilder.cs index 8151c05b51..5ad620a991 100644 --- a/src/Maui/Prism.Maui/Navigation/Builder/INavigationBuilder.cs +++ b/src/Maui/Prism.Maui/Navigation/Builder/INavigationBuilder.cs @@ -1,4 +1,4 @@ -namespace Prism.Navigation.Builder; +namespace Prism.Navigation.Builder; public interface INavigationBuilder { @@ -12,7 +12,7 @@ public interface INavigationBuilder INavigationBuilder UseAbsoluteNavigation(bool absolute); INavigationBuilder UseRelativeNavigation(); - Task GoBackTo(INavigationParameters parameters); + Task GoBackAsync(); Task NavigateAsync(); Task NavigateAsync(Action onError); Task NavigateAsync(Action onSuccess, Action onError); diff --git a/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs b/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs index c22819a44a..5f90e14a12 100644 --- a/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs +++ b/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs @@ -1,4 +1,4 @@ -using Prism.Common; +using Prism.Common; using Prism.Mvvm; namespace Prism.Navigation.Builder; @@ -53,10 +53,10 @@ public INavigationBuilder AddParameter(string key, object value) return this; } - public async Task GoBackTo(INavigationParameters parameters) + public async Task GoBackAsync() { var name = NavigationBuilderExtensions.GetNavigationKey(this); - return await _navigationService.GoBackToAsync(name, parameters); + return await _navigationService.GoBackAsync(name, _navigationParameters); } public Task NavigateAsync() diff --git a/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilderExtensions.cs b/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilderExtensions.cs index b347173bbf..355416bf9f 100644 --- a/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilderExtensions.cs +++ b/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilderExtensions.cs @@ -1,4 +1,4 @@ -using Prism.Common; +using Prism.Common; using Prism.Navigation.Builder; namespace Prism.Navigation; @@ -13,9 +13,6 @@ public static class NavigationBuilderExtensions public static INavigationBuilder CreateBuilder(this INavigationService navigationService) => new NavigationBuilder(navigationService); - public static Task GoBackTo(this INavigationBuilder builder) => - builder.GoBackTo(null); - internal static string GetNavigationKey(object builder) { var vmType = typeof(TViewModel); diff --git a/src/Maui/Prism.Maui/Navigation/INavigationService.cs b/src/Maui/Prism.Maui/Navigation/INavigationService.cs index 816199ca22..f973fad6b9 100644 --- a/src/Maui/Prism.Maui/Navigation/INavigationService.cs +++ b/src/Maui/Prism.Maui/Navigation/INavigationService.cs @@ -1,18 +1,10 @@ -namespace Prism.Navigation; +namespace Prism.Navigation; /// /// Provides page based navigation for ViewModels. /// public interface INavigationService { - /// - /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack. - /// - /// The name of the View to navigate back to - /// The navigation parameters - /// indicating whether the request was successful or if there was an encountered . - Task GoBackToAsync(string name, INavigationParameters parameters); - /// /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack. /// diff --git a/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs b/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs index 89c472930f..ebf1a5c6d0 100644 --- a/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs +++ b/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs @@ -7,15 +7,6 @@ namespace Prism.Navigation; /// public static class INavigationServiceExtensions { - /// - /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack. - /// - /// Service for handling navigation between views - /// The name of the View to navigate back to - /// indicating whether the request was successful or if there was an encountered . - public static Task GoBackToAsync(this INavigationService navigationService, string name) => - navigationService.GoBackToAsync(name, null); - /// /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack. /// diff --git a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs index 77e238c543..852572548c 100644 --- a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs +++ b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs @@ -66,70 +66,6 @@ public PageNavigationService(IContainerProvider container, _pageAccessor = pageAccessor; } - /// - /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack. - /// - /// The name of the View to navigate back to - /// The navigation parameters - /// indicating whether the request was successful or if there was an encountered . - public virtual async Task GoBackToAsync(string name, INavigationParameters parameters) - { - await _semaphore.WaitAsync(); - try - { - parameters ??= new NavigationParameters(); - NavigationSource = PageNavigationSource.NavigationService; - ArgumentException.ThrowIfNullOrEmpty(name); - if (!Registry.IsRegistered(name)) - throw new NavigationException(NavigationException.NoPageIsRegistered, name); - - var page = GetCurrentPage(); - parameters.GetNavigationParametersInternal().Add(KnownInternalParameters.NavigationMode, NavigationMode.Back); - - while (page is not null && ViewModelLocator.GetNavigationName(page) != name) - { - if (IsRoot(GetPageFromWindow(), page)) - throw new NavigationException(NavigationException.CannotPopApplicationMainPage, page); - - var canNavigate = await MvvmHelpers.CanNavigateAsync(page, parameters); - if (!canNavigate) - { - throw new NavigationException(NavigationException.IConfirmNavigationReturnedFalse, page); - } - - var useModalForDoPop = UseModalGoBack(page, parameters); - var previousPage = MvvmHelpers.GetOnNavigatedToTarget(page, Window?.Page, useModalForDoPop); - - bool? animated = null; - if (!parameters.TryGetValue(KnownNavigationParameters.Animated, out var globalAnimated)) - { - animated = true; - } - - var poppedPage = await DoPop(page.Navigation, useModalForDoPop, animated ?? true); - if (poppedPage != null) - { - MvvmHelpers.OnNavigatedFrom(page, parameters); - MvvmHelpers.OnNavigatedTo(previousPage, parameters); - MvvmHelpers.DestroyPage(poppedPage); - } - - page = previousPage; - } - - return Notify(NavigationRequestType.GoBack, parameters); - } - catch (Exception ex) - { - return Notify(NavigationRequestType.GoBack, parameters, ex); - } - finally - { - NavigationSource = PageNavigationSource.Device; - _semaphore.Release(); - } - } - /// /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack. /// diff --git a/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Navigation/NavigationTests.cs b/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Navigation/NavigationTests.cs index 9b4e5ec0a8..021360e8af 100644 --- a/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Navigation/NavigationTests.cs +++ b/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Navigation/NavigationTests.cs @@ -223,7 +223,7 @@ public async Task RelativeNavigation_RemovesPage_AndNavigatesModally() } [Fact] - public async Task GoBackTo_Name_PopsToSpecifiedView() + public async Task GoBack_Name_PopsToSpecifiedView() { var mauiApp = CreateBuilder(prism => prism.CreateWindow("NavigationPage/MockViewA/MockViewB/MockViewC/MockViewD/MockViewE")) .Build(); @@ -237,7 +237,7 @@ public async Task GoBackTo_Name_PopsToSpecifiedView() var result = await navigationPage.CurrentPage.GetContainerProvider() .Resolve() - .GoBackToAsync("MockViewC"); + .GoBackAsync("MockViewC"); Assert.True(result.Success); @@ -245,7 +245,7 @@ public async Task GoBackTo_Name_PopsToSpecifiedView() } [Fact] - public async Task GoBackTo_ViewModel_PopsToSpecifiedView() + public async Task GoBack_ViewModel_PopsToSpecifiedView() { var mauiApp = CreateBuilder(prism => prism.CreateWindow("NavigationPage/MockViewA/MockViewB/MockViewC/MockViewD/MockViewE")) .Build(); @@ -260,7 +260,7 @@ public async Task GoBackTo_ViewModel_PopsToSpecifiedView() var result = await navigationPage.CurrentPage.GetContainerProvider() .Resolve() .CreateBuilder() - .GoBackTo(); + .GoBackAsync(); Assert.True(result.Success);