From 74db7f1c7482bc81f7c7ee1b9a9102b8c98e6772 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Wed, 29 Jan 2020 04:52:52 -0700 Subject: [PATCH] Query parameters were not being applied during simple navigation (#9348) fixes #9344 --- .../ShellModalTests.cs | 44 ++++++++++--------- Xamarin.Forms.Core.UnitTests/ShellTests.cs | 13 ++++++ Xamarin.Forms.Core/Shell/ShellSection.cs | 1 + 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/Xamarin.Forms.Core.UnitTests/ShellModalTests.cs b/Xamarin.Forms.Core.UnitTests/ShellModalTests.cs index 53ad1a623..dab4964f4 100644 --- a/Xamarin.Forms.Core.UnitTests/ShellModalTests.cs +++ b/Xamarin.Forms.Core.UnitTests/ShellModalTests.cs @@ -284,32 +284,41 @@ namespace Xamarin.Forms.Core.UnitTests Assert.IsFalse(page1.Appearing); Assert.IsTrue(page2.Appearing); } - - public class ModalTestPage : ShellLifeCycleTests.LifeCyclePage + [Test] + public async Task BasicQueryStringTest() { - public ModalTestPage() + var shell = new Shell(); + + var item = CreateShellItem(shellSectionRoute: "section2"); + shell.Items.Add(item); + await shell.GoToAsync(new ShellNavigationState($"ModalTestPage?{nameof(ShellTestPage.SomeQueryParameter)}=1234")); + var testPage = (shell.CurrentItem.CurrentItem as IShellSectionController).PresentedPage as ModalTestPageBase; + Assert.AreEqual("1234", testPage.SomeQueryParameter); + } + + + [QueryProperty("SomeQueryParameter", "SomeQueryParameter")] + public class ModalTestPageBase : ShellLifeCycleTests.LifeCyclePage + { + public string SomeQueryParameter { - Shell.SetPresentationMode(this, PresentationMode.Modal); + get; + set; } - protected override void OnAppearing() + public ModalTestPageBase() { - base.OnAppearing(); + Shell.SetPresentationMode(this, PresentationMode.Modal); } } - public class ModalTestPage2 : ShellLifeCycleTests.LifeCyclePage + public class ModalTestPage : ModalTestPageBase { - public ModalTestPage2() - { - Shell.SetPresentationMode(this, PresentationMode.Modal); - } + } - protected override void OnAppearing() - { - base.OnAppearing(); - } + public class ModalTestPage2 : ModalTestPageBase + { } public class ModalNavigationTestPage : NavigationPage @@ -318,11 +327,6 @@ namespace Xamarin.Forms.Core.UnitTests { Shell.SetPresentationMode(this, PresentationMode.Modal); } - - protected override void OnAppearing() - { - base.OnAppearing(); - } } public class SomeCustomPage : Page diff --git a/Xamarin.Forms.Core.UnitTests/ShellTests.cs b/Xamarin.Forms.Core.UnitTests/ShellTests.cs index 3b8554550..2f6a58308 100644 --- a/Xamarin.Forms.Core.UnitTests/ShellTests.cs +++ b/Xamarin.Forms.Core.UnitTests/ShellTests.cs @@ -391,6 +391,19 @@ namespace Xamarin.Forms.Core.UnitTests Assert.AreEqual("4321", testPage.SomeQueryParameter); } + [Test] + public async Task BasicQueryStringTest() + { + var shell = new Shell(); + + var item = CreateShellItem(shellSectionRoute: "section2"); + Routing.RegisterRoute("details", typeof(ShellTestPage)); + shell.Items.Add(item); + await shell.GoToAsync(new ShellNavigationState($"details?{nameof(ShellTestPage.SomeQueryParameter)}=1234")); + var testPage = (shell.CurrentItem.CurrentItem as IShellSectionController).PresentedPage as ShellTestPage; + Assert.AreEqual("1234", testPage.SomeQueryParameter); + } + [Test] public async Task NavigationWithQueryStringAndNoDataTemplate() diff --git a/Xamarin.Forms.Core/Shell/ShellSection.cs b/Xamarin.Forms.Core/Shell/ShellSection.cs index f5ae5ec25..607990eff 100644 --- a/Xamarin.Forms.Core/Shell/ShellSection.cs +++ b/Xamarin.Forms.Core/Shell/ShellSection.cs @@ -406,6 +406,7 @@ namespace Xamarin.Forms var isModal = (Shell.GetPresentationMode(content) & PresentationMode.Modal) == PresentationMode.Modal; + Shell.ApplyQueryAttributes(content, queryData, isLast); if (isModal) { modalPageStacks.Add(content);