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

fix: Navigation inserts page before current page in NavigationPage stack #2835

Merged
merged 1 commit into from
Mar 5, 2023
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
7 changes: 4 additions & 3 deletions src/Maui/Prism.Maui/Navigation/PageNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,9 @@ protected virtual async Task UseReverseNavigation(Page currentPage, string nextS
}

var pageOffset = currentPage.Navigation.NavigationStack.Count;
if (currentPage.Navigation.NavigationStack.Count > 2)
pageOffset = currentPage.Navigation.NavigationStack.Count - 1;
// NOTE: Disabled due to Issue 2232
//if (currentPage.Navigation.NavigationStack.Count > 2)
// pageOffset = currentPage.Navigation.NavigationStack.Count - 1;

var onNavigatedFromTarget = currentPage;
if (currentPage is NavigationPage navPage && navPage.CurrentPage != null)
Expand Down Expand Up @@ -1208,4 +1209,4 @@ private Page GetPageFromWindow()
}
#endif
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Prism.Common;
using Prism.Controls;
using Prism.DryIoc.Maui.Tests.Mocks.ViewModels;
using Prism.DryIoc.Maui.Tests.Mocks.Views;
Expand Down Expand Up @@ -188,6 +189,33 @@ public async Task GoBackTo_ViewModel_PopsToSpecifiedView()
Assert.IsType<MockViewC>(navigationPage.CurrentPage);
}

[Fact]
public async Task GoBack_Issue2232()
{
var mauiApp = CreateBuilder(prism => prism.OnAppStart("NavigationPage/MockViewA"))
.Build();
var window = GetWindow(mauiApp);

Assert.IsAssignableFrom<NavigationPage>(window.Page);
var navigationPage = (NavigationPage)window.Page;

await MvvmHelpers.InvokeViewAndViewModelActionAsync<MockViewModelBase>(navigationPage.CurrentPage, x => x.NavigateTo("MockViewB"));
Assert.IsType<MockViewB>(navigationPage.CurrentPage);
await MvvmHelpers.InvokeViewAndViewModelActionAsync<MockViewModelBase>(navigationPage.CurrentPage, x => x.NavigateTo("MockViewC"));
Assert.IsType<MockViewC>(navigationPage.CurrentPage);
await MvvmHelpers.InvokeViewAndViewModelActionAsync<MockViewModelBase>(navigationPage.CurrentPage, x => x.NavigateTo("MockViewD/MockViewE"));
Assert.IsType<MockViewE>(navigationPage.CurrentPage);

await MvvmHelpers.InvokeViewAndViewModelActionAsync<MockViewModelBase>(navigationPage.CurrentPage, x => x.GoBack());
Assert.IsType<MockViewD>(navigationPage.CurrentPage);
await MvvmHelpers.InvokeViewAndViewModelActionAsync<MockViewModelBase>(navigationPage.CurrentPage, x => x.GoBack());
Assert.IsType<MockViewC>(navigationPage.CurrentPage);
await MvvmHelpers.InvokeViewAndViewModelActionAsync<MockViewModelBase>(navigationPage.CurrentPage, x => x.GoBack());
Assert.IsType<MockViewB>(navigationPage.CurrentPage);
await MvvmHelpers.InvokeViewAndViewModelActionAsync<MockViewModelBase>(navigationPage.CurrentPage, x => x.GoBack());
Assert.IsType<MockViewA>(navigationPage.CurrentPage);
}

private void TestPage(Page page)
{
Assert.NotNull(page.BindingContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ protected MockViewModelBase(IPageAccessor pageAccessor, INavigationService navig

public INavigationService NavigationService { get; }

public Task<INavigationResult> GoBack() => NavigationService.GoBackAsync();

public Task<INavigationResult> NavigateTo(string uri) => NavigationService.NavigateAsync(uri);

public Page Page => _pageAccessor.Page;

public bool StopNavigation { get; set; }

public bool CanNavigate(INavigationParameters parameters) =>
!StopNavigation;
}
}