mirror of
https://github.com/AlexMacocian/Net.Maui.Extensions.git
synced 2026-07-15 14:59:31 +00:00
GoBackTo page implementation
This commit is contained in:
@@ -12,5 +12,8 @@ public interface INavigationService
|
||||
|
||||
void GoBack();
|
||||
|
||||
void GoBackTo<TPageType>()
|
||||
where TPageType : ContentPage;
|
||||
|
||||
void GoBackToRoot();
|
||||
}
|
||||
|
||||
@@ -53,6 +53,22 @@ internal sealed class NavigationService : INavigationService
|
||||
this.ShowCurrentPage();
|
||||
}
|
||||
|
||||
public void GoBackTo<TPageType>() where TPageType : ContentPage
|
||||
{
|
||||
var scopedLogger = this.logger.CreateScopedLogger();
|
||||
scopedLogger.LogDebug($"Going back to {typeof(TPageType).Name}");
|
||||
while (
|
||||
this.navigationStack.Count > 1 &&
|
||||
this.navigationStack.TryPeek(out var context) &&
|
||||
context.Page is not TPageType)
|
||||
{
|
||||
this.navigationStack.Pop();
|
||||
context.Scope?.Dispose();
|
||||
}
|
||||
|
||||
this.ShowCurrentPage();
|
||||
}
|
||||
|
||||
public TPageType GoTo<TPageType, TViewModelType>(TViewModelType? viewModel = default)
|
||||
where TPageType : ContentPage, IPageViewModel<TViewModelType>
|
||||
where TViewModelType : class, INotifyPropertyChanged, new()
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Version>0.2.11</Version>
|
||||
<Version>0.2.12</Version>
|
||||
<Authors>Alexandru Macocian</Authors>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
|
||||
Reference in New Issue
Block a user