From 4b249ccb1a415461b39c0e97c5bd1b7ec5762b3e Mon Sep 17 00:00:00 2001 From: Bernd Hirschmann Date: Fri, 8 Mar 2024 15:22:14 +0100 Subject: [PATCH 1/2] ref: remove legacy GoBackTo --- .../Navigation/Builder/INavigationBuilder.cs | 4 +- .../Navigation/Builder/NavigationBuilder.cs | 11 +++- .../Builder/NavigationBuilderExtensions.cs | 5 +- .../Navigation/INavigationService.cs | 10 +--- .../INavigationServiceExtensions.cs | 3 +- .../Navigation/PageNavigationService.cs | 59 +------------------ .../Fixtures/Navigation/NavigationTests.cs | 8 +-- 7 files changed, 24 insertions(+), 76 deletions(-) diff --git a/src/Maui/Prism.Maui/Navigation/Builder/INavigationBuilder.cs b/src/Maui/Prism.Maui/Navigation/Builder/INavigationBuilder.cs index 8151c05b51..9fb4920a49 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,9 @@ public interface INavigationBuilder INavigationBuilder UseAbsoluteNavigation(bool absolute); INavigationBuilder UseRelativeNavigation(); + [Obsolete($"Use {nameof(GoBackAsync)} instead.")] 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..d2340f0385 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,17 @@ public INavigationBuilder AddParameter(string key, object value) return this; } + [Obsolete($"Use {nameof(GoBackAsync)} instead.")] public async Task GoBackTo(INavigationParameters parameters) { var name = NavigationBuilderExtensions.GetNavigationKey(this); - return await _navigationService.GoBackToAsync(name, parameters); + return await _navigationService.GoBackAsync(name, parameters); + } + + public async Task GoBackAsync() + { + var name = NavigationBuilderExtensions.GetNavigationKey(this); + 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..a789476ad6 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,8 +13,9 @@ public static class NavigationBuilderExtensions public static INavigationBuilder CreateBuilder(this INavigationService navigationService) => new NavigationBuilder(navigationService); + [Obsolete($"Use {nameof(INavigationBuilder.GoBackAsync)} instead.")] public static Task GoBackTo(this INavigationBuilder builder) => - builder.GoBackTo(null); + builder.GoBackAsync(); internal static string GetNavigationKey(object builder) { 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..749cb51221 100644 --- a/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs +++ b/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs @@ -13,8 +13,9 @@ public static class INavigationServiceExtensions /// 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 . + [Obsolete($"Use {nameof(GoBackAsync)} instead.")] public static Task GoBackToAsync(this INavigationService navigationService, string name) => - navigationService.GoBackToAsync(name, null); + navigationService.GoBackAsync(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..ab98d3ac3c 100644 --- a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs +++ b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs @@ -72,63 +72,8 @@ public PageNavigationService(IContainerProvider container, /// 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(); - } - } + public virtual Task GoBackToAsync(string name, INavigationParameters parameters) + => GoBackAsync(name, parameters); /// /// 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); From acee603a64c61e737abf4c23a7706a571eab477b Mon Sep 17 00:00:00 2001 From: Bernd Hirschmann Date: Tue, 26 Mar 2024 08:45:45 +0100 Subject: [PATCH 2/2] remove obsolete methods --- .../Navigation/Builder/INavigationBuilder.cs | 2 -- .../Prism.Maui/Navigation/Builder/NavigationBuilder.cs | 7 ------- .../Navigation/Builder/NavigationBuilderExtensions.cs | 4 ---- .../Navigation/INavigationServiceExtensions.cs | 10 ---------- .../Prism.Maui/Navigation/PageNavigationService.cs | 9 --------- 5 files changed, 32 deletions(-) diff --git a/src/Maui/Prism.Maui/Navigation/Builder/INavigationBuilder.cs b/src/Maui/Prism.Maui/Navigation/Builder/INavigationBuilder.cs index 9fb4920a49..5ad620a991 100644 --- a/src/Maui/Prism.Maui/Navigation/Builder/INavigationBuilder.cs +++ b/src/Maui/Prism.Maui/Navigation/Builder/INavigationBuilder.cs @@ -12,8 +12,6 @@ public interface INavigationBuilder INavigationBuilder UseAbsoluteNavigation(bool absolute); INavigationBuilder UseRelativeNavigation(); - [Obsolete($"Use {nameof(GoBackAsync)} instead.")] - Task GoBackTo(INavigationParameters parameters); Task GoBackAsync(); Task NavigateAsync(); Task NavigateAsync(Action onError); diff --git a/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs b/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs index d2340f0385..5f90e14a12 100644 --- a/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs +++ b/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs @@ -53,13 +53,6 @@ public INavigationBuilder AddParameter(string key, object value) return this; } - [Obsolete($"Use {nameof(GoBackAsync)} instead.")] - public async Task GoBackTo(INavigationParameters parameters) - { - var name = NavigationBuilderExtensions.GetNavigationKey(this); - return await _navigationService.GoBackAsync(name, parameters); - } - public async Task GoBackAsync() { var name = NavigationBuilderExtensions.GetNavigationKey(this); diff --git a/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilderExtensions.cs b/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilderExtensions.cs index a789476ad6..355416bf9f 100644 --- a/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilderExtensions.cs +++ b/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilderExtensions.cs @@ -13,10 +13,6 @@ public static class NavigationBuilderExtensions public static INavigationBuilder CreateBuilder(this INavigationService navigationService) => new NavigationBuilder(navigationService); - [Obsolete($"Use {nameof(INavigationBuilder.GoBackAsync)} instead.")] - public static Task GoBackTo(this INavigationBuilder builder) => - builder.GoBackAsync(); - internal static string GetNavigationKey(object builder) { var vmType = typeof(TViewModel); diff --git a/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs b/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs index 749cb51221..ebf1a5c6d0 100644 --- a/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs +++ b/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs @@ -7,16 +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 . - [Obsolete($"Use {nameof(GoBackAsync)} instead.")] - public static Task GoBackToAsync(this INavigationService navigationService, string name) => - navigationService.GoBackAsync(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 ab98d3ac3c..852572548c 100644 --- a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs +++ b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs @@ -66,15 +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 Task GoBackToAsync(string name, INavigationParameters parameters) - => GoBackAsync(name, parameters); - /// /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack. ///