Reverse the order of assigning the Current Items on Shell (#8630)
authorShane Neuville <shneuvil@microsoft.com>
Tue, 3 Dec 2019 21:18:03 +0000 (14:18 -0700)
committerGitHub <noreply@github.com>
Tue, 3 Dec 2019 21:18:03 +0000 (14:18 -0700)
* Failing Unit test for #8624

* - Set Current Item from the bottom up

Xamarin.Forms.Core.UnitTests/ShellLifeCycleTests.cs
Xamarin.Forms.Core/Shell/Shell.cs

index bcb98d1..e87189f 100644 (file)
@@ -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()
index 62b07b3..8327d6a 100644 (file)
@@ -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)