[Shell] Apply Query string parameters even if they aren't present and correctly apply them to nested pages (#6695)
* apply query string parameters if they aren't there - apply query string parameters correctly to nested pages * Update Xamarin.Forms.Core/Shell/Shell.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> fixes #6543
This commit is contained in:
Родитель
22f39546de
Коммит
daeb45b158
|
@ -42,7 +42,11 @@ namespace Xamarin.Forms.Core.UnitTests
|
||||||
[QueryProperty("SomeQueryParameter", "SomeQueryParameter")]
|
[QueryProperty("SomeQueryParameter", "SomeQueryParameter")]
|
||||||
public class ShellTestPage : ContentPage
|
public class ShellTestPage : ContentPage
|
||||||
{
|
{
|
||||||
public string SomeQueryParameter { get; set; }
|
public string SomeQueryParameter
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ShellItem CreateShellItem(TemplatedPage page = null, bool asImplicit = false, string shellContentRoute = null, string shellSectionRoute = null, string shellItemRoute = null)
|
protected ShellItem CreateShellItem(TemplatedPage page = null, bool asImplicit = false, string shellContentRoute = null, string shellSectionRoute = null, string shellItemRoute = null)
|
||||||
|
|
|
@ -220,6 +220,64 @@ namespace Xamarin.Forms.Core.UnitTests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task NavigationWithQueryStringThenWithoutQueryString()
|
||||||
|
{
|
||||||
|
var shell = new Shell();
|
||||||
|
|
||||||
|
var one = new ShellItem { Route = "one" };
|
||||||
|
var two = new ShellItem { Route = "two" };
|
||||||
|
|
||||||
|
var tabone = MakeSimpleShellSection("tabone", "content");
|
||||||
|
var tabfour = MakeSimpleShellSection("tabfour", "content", null);
|
||||||
|
|
||||||
|
one.Items.Add(tabone);
|
||||||
|
two.Items.Add(tabfour);
|
||||||
|
|
||||||
|
shell.Items.Add(one);
|
||||||
|
shell.Items.Add(two);
|
||||||
|
|
||||||
|
ShellTestPage pagetoTest = new ShellTestPage();
|
||||||
|
await shell.GoToAsync(new ShellNavigationState($"//two/tabfour/content?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));
|
||||||
|
two.CurrentItem.CurrentItem.ContentTemplate = new DataTemplate(() =>
|
||||||
|
{
|
||||||
|
pagetoTest = new ShellTestPage();
|
||||||
|
pagetoTest.BindingContext = pagetoTest;
|
||||||
|
return pagetoTest;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
await shell.GoToAsync(new ShellNavigationState($"//one/tabone/content"));
|
||||||
|
await shell.GoToAsync(new ShellNavigationState($"//two/tabfour/content"));
|
||||||
|
|
||||||
|
var page = (two.CurrentItem.CurrentItem as IShellContentController).GetOrCreateContent();
|
||||||
|
Assert.AreEqual(null, (page as ShellTestPage).SomeQueryParameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task NavigationBetweenShellContentsPassesQueryString()
|
||||||
|
{
|
||||||
|
var shell = new Shell();
|
||||||
|
|
||||||
|
var item = CreateShellItem(shellSectionRoute: "section2");
|
||||||
|
var content = CreateShellContent(shellContentRoute: "content");
|
||||||
|
item.Items[0].Items.Add(content);
|
||||||
|
|
||||||
|
Routing.RegisterRoute("details", typeof(ShellTestPage));
|
||||||
|
|
||||||
|
shell.Items.Add(item);
|
||||||
|
|
||||||
|
|
||||||
|
await shell.GoToAsync(new ShellNavigationState($"//section2/details?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));
|
||||||
|
await shell.GoToAsync(new ShellNavigationState($"//content?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));
|
||||||
|
await shell.GoToAsync(new ShellNavigationState($"//section2/details?{nameof(ShellTestPage.SomeQueryParameter)}=4321"));
|
||||||
|
|
||||||
|
var testPage = (shell.CurrentItem.CurrentItem as IShellSectionController).PresentedPage as ShellTestPage;
|
||||||
|
Assert.AreEqual("4321", testPage.SomeQueryParameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task NavigationWithQueryStringAndNoDataTemplate()
|
public async Task NavigationWithQueryStringAndNoDataTemplate()
|
||||||
{
|
{
|
||||||
|
@ -239,7 +297,6 @@ namespace Xamarin.Forms.Core.UnitTests
|
||||||
|
|
||||||
await shell.GoToAsync(new ShellNavigationState($"//two/tabfour/content?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));
|
await shell.GoToAsync(new ShellNavigationState($"//two/tabfour/content?{nameof(ShellTestPage.SomeQueryParameter)}=1234"));
|
||||||
Assert.AreEqual("1234", (two.CurrentItem.CurrentItem.Content as ShellTestPage).SomeQueryParameter);
|
Assert.AreEqual("1234", (two.CurrentItem.CurrentItem.Content as ShellTestPage).SomeQueryParameter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -449,9 +449,6 @@ namespace Xamarin.Forms
|
||||||
|
|
||||||
internal static void ApplyQueryAttributes(Element element, IDictionary<string, string> query, bool isLastItem)
|
internal static void ApplyQueryAttributes(Element element, IDictionary<string, string> query, bool isLastItem)
|
||||||
{
|
{
|
||||||
if (query.Count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
string prefix = "";
|
string prefix = "";
|
||||||
if (!isLastItem)
|
if (!isLastItem)
|
||||||
{
|
{
|
||||||
|
@ -487,7 +484,7 @@ namespace Xamarin.Forms
|
||||||
filteredQuery.Add(key, q.Value);
|
filteredQuery.Add(key, q.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baseShellItem != null)
|
if (baseShellItem is ShellContent)
|
||||||
baseShellItem.ApplyQueryAttributes(filteredQuery);
|
baseShellItem.ApplyQueryAttributes(filteredQuery);
|
||||||
else if (isLastItem)
|
else if (isLastItem)
|
||||||
element.SetValue(ShellContent.QueryAttributesProperty, query);
|
element.SetValue(ShellContent.QueryAttributesProperty, query);
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Xamarin.Forms
|
||||||
var shellSection = request.Request.Section;
|
var shellSection = request.Request.Section;
|
||||||
|
|
||||||
if (shellSection == null)
|
if (shellSection == null)
|
||||||
return Task.FromResult(true);
|
shellSection = Items[0];
|
||||||
|
|
||||||
Shell.ApplyQueryAttributes(shellSection, queryData, request.Request.Content == null);
|
Shell.ApplyQueryAttributes(shellSection, queryData, request.Request.Content == null);
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace Xamarin.Forms
|
||||||
ShellContent shellContent = request.Request.Content;
|
ShellContent shellContent = request.Request.Content;
|
||||||
|
|
||||||
if (shellContent == null)
|
if (shellContent == null)
|
||||||
return Task.FromResult(true);
|
shellContent = Items[0];
|
||||||
|
|
||||||
if (request.Request.GlobalRoutes.Count > 0)
|
if (request.Request.GlobalRoutes.Count > 0)
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче