mirror of
https://github.com/AlexMacocian/Net.Maui.Extensions.git
synced 2026-07-15 14:59:31 +00:00
NavigationService improvements
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
public interface INavigationService
|
||||
{
|
||||
void GoTo<T>(bool animated = false)
|
||||
ContentPage? GetCurrent();
|
||||
|
||||
T GoTo<T>()
|
||||
where T : ContentPage;
|
||||
|
||||
void GoBack(bool animated = false);
|
||||
void GoBack();
|
||||
|
||||
void GoBackToRoot(bool animated = false);
|
||||
void GoBackToRoot();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ internal sealed class NavigationService : INavigationService
|
||||
this.logger = logger.ThrowIfNull();
|
||||
}
|
||||
|
||||
public void GoBack(bool animated = false)
|
||||
public void GoBack()
|
||||
{
|
||||
var scopedLogger = this.logger.CreateScopedLogger();
|
||||
if (this.navigationStack.Count <= 1)
|
||||
@@ -40,7 +40,7 @@ internal sealed class NavigationService : INavigationService
|
||||
this.ShowCurrentPage();
|
||||
}
|
||||
|
||||
public void GoBackToRoot(bool animated = false)
|
||||
public void GoBackToRoot()
|
||||
{
|
||||
var scopedLogger = this.logger.CreateScopedLogger();
|
||||
scopedLogger.LogDebug("Going back to root");
|
||||
@@ -52,7 +52,7 @@ internal sealed class NavigationService : INavigationService
|
||||
this.ShowCurrentPage();
|
||||
}
|
||||
|
||||
public void GoTo<T>(bool animated = false) where T : ContentPage
|
||||
public T GoTo<T>() where T : ContentPage
|
||||
{
|
||||
var scopedLogger = this.logger.CreateScopedLogger();
|
||||
scopedLogger.LogDebug($"Going to {typeof(T).Name}");
|
||||
@@ -60,6 +60,17 @@ internal sealed class NavigationService : INavigationService
|
||||
var context = this.GetScopedPageAndProvider<T>();
|
||||
this.navigationStack.Push(context);
|
||||
this.ShowCurrentPage();
|
||||
return context.Page?.ThrowIfNull().Cast<T>().ThrowIfNull()!;
|
||||
}
|
||||
|
||||
public ContentPage? GetCurrent()
|
||||
{
|
||||
if (this.navigationStack.TryPeek(out var context))
|
||||
{
|
||||
return context.Page?.ThrowIfNull();
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public void SetNavigationRoot(ExtendedApplication extendedApplication, Type rootPageType)
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Version>0.2.4</Version>
|
||||
<Version>0.2.5</Version>
|
||||
<Authors>Alexandru Macocian</Authors>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
|
||||
Reference in New Issue
Block a user