Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Route Shell Modal Navigation through ShellSection (#15053)
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen authored Jan 14, 2022
1 parent b411491 commit 37589f0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Xamarin.Forms.Core.UnitTests/ShellModalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,34 @@ public async Task CanCancelPushModalAsync()
Assert.AreEqual(0, shell.Navigation.ModalStack.Count);
}

[Test]
public async Task PopModalFromShellNavigationProxy()
{
Routing.RegisterRoute("ModalTestPage", typeof(ModalTestPage));
Shell shell = new Shell();
shell.Items.Add(CreateShellItem(shellItemRoute: "NewRoute"));

await shell.GoToAsync("ModalTestPage");
await shell.Navigation.PopModalAsync();

Assert.AreEqual("//NewRoute", shell.CurrentState.Location.ToString());
}

[Test]
public async Task PushModalFromShellNavigationProxy()
{
ModalTestPage modalTestPage = new ModalTestPage();
Routing.SetRoute(modalTestPage, "ModalTestPage");

Routing.RegisterRoute("ModalTestPage", typeof(ModalTestPage));
Shell shell = new Shell();
shell.Items.Add(CreateShellItem(shellItemRoute: "NewRoute"));
await shell.Navigation.PushModalAsync(modalTestPage);

Assert.AreEqual("//NewRoute/ModalTestPage", shell.CurrentState.Location.ToString());
}


[QueryProperty("SomeQueryParameter", "SomeQueryParameter")]
public class ModalTestPageBase : ShellLifeCycleTests.LifeCyclePage
{
Expand Down
15 changes: 15 additions & 0 deletions Xamarin.Forms.Core/Shell/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,13 @@ class NavigationImpl : NavigationProxy

protected override async Task<Page> OnPopModal(bool animated)
{
if (!_shell.NavigationManager.AccumulateNavigatedEvents)
{
var page = _shell.CurrentPage;
await _shell.GoToAsync("..", animated);
return page;
}

if (ModalStack.Count > 0)
ModalStack[ModalStack.Count - 1].SendDisappearing();

Expand All @@ -1327,6 +1334,14 @@ protected override async Task<Page> OnPopModal(bool animated)

protected override async Task OnPushModal(Page modal, bool animated)
{
if (!_shell.NavigationManager.AccumulateNavigatedEvents)
{
// This will route the modal push through the shell section which is setup
// to update the shell state after a modal push
await _shell.CurrentItem.CurrentItem.Navigation.PushModalAsync(modal, animated);
return;
}

if (ModalStack.Count == 0)
_shell.CurrentItem.SendDisappearing();

Expand Down

0 comments on commit 37589f0

Please sign in to comment.