Skip to content

Commit

Permalink
Navigation RemovePageInstruction not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Civale, Luca authored and Civale, Luca committed Jan 20, 2024
1 parent 1eb46ae commit 2c281fa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Maui/Prism.Maui/Navigation/PageNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ public virtual async Task<INavigationResult> GoBackToAsync(string name, INavigat
public virtual async Task<INavigationResult> GoBackAsync(INavigationParameters parameters)
{
await _semaphore.WaitAsync();

INavigationResult result = await GoBackInternalAsync(parameters);

_semaphore.Release();

return result;
}

private async Task<INavigationResult> GoBackInternalAsync(INavigationParameters parameters)
{
Page page = null;
try
{
Expand Down Expand Up @@ -174,7 +184,6 @@ public virtual async Task<INavigationResult> GoBackAsync(INavigationParameters p
finally
{
NavigationSource = PageNavigationSource.Device;
_semaphore.Release();
}

return Notify(NavigationRequestType.GoBack, parameters, GetGoBackException(page, GetPageFromWindow()));
Expand Down Expand Up @@ -468,7 +477,7 @@ private Task RemoveAndGoBack(Page currentPage, string nextSegment, Queue<string>

RemovePagesFromNavigationPage(currentPage, pagesToRemove);

return GoBackAsync(parameters);
return GoBackInternalAsync(parameters);
}

private async Task RemoveAndPush(Page currentPage, string nextSegment, Queue<string> segments, INavigationParameters parameters, bool? useModalNavigation, bool animated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ public async Task RelativeNavigation_RemovesPage_AndNavigates()
Assert.Equal(2, rootPage.Navigation.NavigationStack.Count);
}

[Fact(Timeout = 5000)]
public async Task Issue3047_RelativeNavigation_RemovesPage_AndGoBack()
{
var mauiApp = CreateBuilder(prism => prism.CreateWindow("NavigationPage/MockViewA/MockViewB"))
.Build();
var window = GetWindow(mauiApp);

var rootPage = window.Page as NavigationPage;
Assert.NotNull(rootPage);
TestPage(rootPage);
var currentPage = rootPage.CurrentPage;
Assert.IsType<MockViewB>(currentPage);
TestPage(currentPage);
var container = currentPage.GetContainerProvider();
var navService = container.Resolve<INavigationService>();
Assert.Equal(2, rootPage.Navigation.NavigationStack.Count);
await navService.NavigateAsync("../");
Assert.IsType<MockViewA>(rootPage.CurrentPage);
TestPage(rootPage.CurrentPage);
Assert.Single(rootPage.Navigation.NavigationStack);
}

[Fact]
public async Task AbsoluteNavigation_ResetsWindowPage()
{
Expand Down

0 comments on commit 2c281fa

Please sign in to comment.