GoBackTo page implementation

This commit is contained in:
2024-09-03 22:26:11 +02:00
parent 5098909f97
commit e4a8fa270a
3 changed files with 20 additions and 1 deletions
@@ -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>