Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation RemovePageInstruction not working correctly #3053

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading