Skip to content

Commit

Permalink
Merge pull request #23 from nalu-development/feature/fix-crash-on-com…
Browse files Browse the repository at this point in the history
…plex-navigation

Fixes a crash on complex navigation
  • Loading branch information
albyrock87 authored Mar 27, 2024
2 parents b802f57 + 75fd512 commit 95595d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Source/Nalu.Maui.Navigation/Internals/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private async Task<bool> ExecuteAbsoluteNavigationAsync(INavigationInfo navigati
.SelectMany(section => section.Contents)
.Where(content => content.Page is not null)
.OrderByDescending(content => content.Parent == currentSection)
.ThenBy(content => content.Parent)
.ThenBy(content => content.Parent.SegmentName)
.ThenByDescending(content => content == currentContent)];
}
else
Expand Down
36 changes: 25 additions & 11 deletions Tests/Nalu.Maui.Test/Navigation/NavigationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,20 +626,30 @@ public async Task NavigationServiceWhenDoingAbsoluteNavigationOnSameItemButDiffe
[Fact(DisplayName = "NavigationService, when doing absolute navigation on different item, should pop navigation stacks")]
public async Task NavigationServiceWhenDoingAbsoluteNavigationOnDifferentItemShouldPopNavigationStacks()
{
ConfigureTestAsync("c1,c5");
await _navigationService.InitializeAsync(_shellProxy, nameof(Page1), null);
ConfigureTestAsync("i1[c1,c2,c3],c5");
await _navigationService.InitializeAsync(_shellProxy, nameof(Page2), null);
await _navigationService.GoToAsync(Navigation.Absolute().ShellContent<IPage3Model>());
await _navigationService.GoToAsync(Navigation.Absolute().ShellContent<IPage1Model>());
var shellContent1 = _shellProxy.GetContent(nameof(Page1));
var shellSection = shellContent1.Parent;
var shellContent2 = _shellProxy.GetContent(nameof(Page2));
var shellContent3 = _shellProxy.GetContent(nameof(Page3));
var shellSection1 = shellContent1.Parent;
var page1 = shellContent1.Page!;
var model1 = (IPage1Model)page1.BindingContext;

await _navigationService.GoToAsync(Navigation.Relative().Push<IPage2Model>());
var navigationStackPages = shellSection.GetNavigationStack().ToList();
var page2 = navigationStackPages[1].Page;
var page2 = shellContent2.Page!;
var model2 = (IPage2Model)page2.BindingContext;
var page3 = shellContent3.Page!;
var model3 = (IPage3Model)page3.BindingContext;

await _navigationService.GoToAsync(Navigation.Relative().Push<IPage4Model>());
var navigationStackPages = shellSection1.GetNavigationStack().ToList();
var page4 = navigationStackPages[1].Page;
var model4 = (IPage4Model)page4.BindingContext;

model1.ClearReceivedCalls();
model2.ClearReceivedCalls();
model3.ClearReceivedCalls();
model4.ClearReceivedCalls();
_shellProxy.ClearReceivedCalls();

await _navigationService.GoToAsync(Navigation.Absolute().ShellContent<IPage5Model>());
Expand All @@ -649,15 +659,19 @@ public async Task NavigationServiceWhenDoingAbsoluteNavigationOnDifferentItemSho

Received.InOrder(() =>
{
model2.OnDisappearingAsync();
model2.OnLeavingAsync();
_shellProxy.PopAsync(shellSection);
model4.OnDisappearingAsync();
model4.OnLeavingAsync();
_shellProxy.PopAsync(shellSection1);
model1.OnLeavingAsync();
model2.OnLeavingAsync();
model3.OnLeavingAsync();
model5.OnEnteringAsync();
_shellProxy.SelectContentAsync(nameof(Page5));
model5.OnAppearingAsync();
model2.Dispose();
model4.Dispose();
model1.Dispose();
model2.Dispose();
model3.Dispose();
});
}

Expand Down

0 comments on commit 95595d0

Please sign in to comment.