Route Shell Modal Navigation through ShellSection (#15053)

This commit is contained in:
Shane Neuville 2022-01-14 02:15:48 -06:00 коммит произвёл GitHub
Родитель b411491f23
Коммит 37589f0f41
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 43 добавлений и 0 удалений

Просмотреть файл

@ -431,6 +431,34 @@ namespace Xamarin.Forms.Core.UnitTests
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
{

Просмотреть файл

@ -1308,6 +1308,13 @@ namespace Xamarin.Forms
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();
@ -1327,6 +1334,14 @@ namespace Xamarin.Forms
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();