From c6321a74e80f4d05f2c28a68b24022196aeaf04c Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Tue, 3 Dec 2019 14:18:03 -0700 Subject: [PATCH] Reverse the order of assigning the Current Items on Shell (#8630) * Failing Unit test for #8624 * - Set Current Item from the bottom up --- .../ShellLifeCycleTests.cs | 28 ++++++++++++++++++++++ Xamarin.Forms.Core/Shell/Shell.cs | 20 ++++++++-------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Xamarin.Forms.Core.UnitTests/ShellLifeCycleTests.cs b/Xamarin.Forms.Core.UnitTests/ShellLifeCycleTests.cs index bcb98d1..e87189f 100644 --- a/Xamarin.Forms.Core.UnitTests/ShellLifeCycleTests.cs +++ b/Xamarin.Forms.Core.UnitTests/ShellLifeCycleTests.cs @@ -39,6 +39,34 @@ namespace Xamarin.Forms.Core.UnitTests Assert.True(contentAppearing, "Content Appearing"); } + [Test] + public void MisfiringOfAppearingWithMultipleTabs() + { + Shell shell = new Shell(); + + var item0 = CreateShellItem(shellContentRoute: "Outbox", templated: true); + var item1 = CreateShellItem(shellSectionRoute: "RequestType1", shellContentRoute: "RequestType1Details", templated: true); + var section2 = CreateShellSection(shellSectionRoute: "RequestType2", shellContentRoute: "RequestType2Dates", templated: true); + + item1.Items.Add(section2); + shell.Items.Add(item0); + shell.Items.Add(item1); + + int appearingCounter = 0; + shell.GoToAsync("//Outbox"); + shell.GoToAsync("//RequestType1Details"); + shell.GoToAsync("//Outbox"); + + + item1.Items[0].Appearing += (_, __) => + { + appearingCounter++; + }; + + shell.GoToAsync("//RequestType2Dates"); + Assert.AreEqual(0, appearingCounter); + } + [Test] public void AppearingOnCreateFromTemplate() diff --git a/Xamarin.Forms.Core/Shell/Shell.cs b/Xamarin.Forms.Core/Shell/Shell.cs index 62b07b3..8327d6a 100644 --- a/Xamarin.Forms.Core/Shell/Shell.cs +++ b/Xamarin.Forms.Core/Shell/Shell.cs @@ -414,9 +414,13 @@ namespace Xamarin.Forms { ApplyQueryAttributes(shellItem, queryData, navigationRequest.Request.Section == null); - if (CurrentItem != shellItem) + if (shellSection != null && shellContent != null) { - SetValueFromRenderer(CurrentItemProperty, shellItem); + Shell.ApplyQueryAttributes(shellContent, queryData, navigationRequest.Request.GlobalRoutes.Count == 0); + if (shellSection.CurrentItem != shellContent) + { + shellSection.SetValueFromRenderer(ShellSection.CurrentItemProperty, shellContent); + } } if (shellSection != null) @@ -426,15 +430,11 @@ namespace Xamarin.Forms { shellItem.SetValueFromRenderer(ShellItem.CurrentItemProperty, shellSection); } + } - if (shellContent != null) - { - Shell.ApplyQueryAttributes(shellContent, queryData, navigationRequest.Request.GlobalRoutes.Count == 0); - if (shellSection.CurrentItem != shellContent) - { - shellSection.SetValueFromRenderer(ShellSection.CurrentItemProperty, shellContent); - } - } + if (CurrentItem != shellItem) + { + SetValueFromRenderer(CurrentItemProperty, shellItem); } if (navigationRequest.Request.GlobalRoutes.Count > 0) -- 2.7.4