--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Text;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UITests;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Github, 8008, "Removing Shell Item can cause Shell to try and set a MenuItem as the default visible item")]
+#if UITEST
+ [NUnit.Framework.Category(UITestCategories.Shell)]
+#endif
+ public class Issue8008 : TestShell
+ {
+ ShellItem item1;
+ protected override void Init()
+ {
+ item1 = AddContentPage();
+
+ Items.Add(new MenuShellItem(new MenuItem()
+ {
+ Text = "Menu Item",
+ Command = new Command(() =>
+ {
+ throw new Exception("I shouldn't execute after removing an item");
+ })
+ }));
+
+ AddContentPage(new ContentPage()
+ {
+ Content = new StackLayout()
+ {
+ Children =
+ {
+ new Label()
+ {
+ Text = "If you are reading this then this test has passed",
+ AutomationId = "Success"
+ }
+ }
+ }
+ });
+ Device.BeginInvokeOnMainThread(() =>
+ {
+ this.Items.Remove(item1);
+ });
+
+ }
+
+#if UITEST
+ [Test]
+ public void RemovingShellItemCorrectlyPicksNextValidShellItemAsVisibleShellItem()
+ {
+ RunningApp.WaitForElement("Success");
+ }
+#endif
+ }
+}
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewHeaderFooterTemplate.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewHeaderFooterView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewItemsUpdatingScrollMode.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Issue8008.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue6640.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7556.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7329.cs" />
{
base.OnChildAdded(child);
- if (child is ShellItem shellItem && CurrentItem == null && !(child is MenuShellItem))
+ if (child is ShellItem shellItem && CurrentItem == null && ValidDefaultShellItem(child))
{
((IShellController)this).OnFlyoutItemSelected(shellItem);
}
{
base.OnChildRemoved(child);
- if (child == CurrentItem && Items.Count > 0)
+ if (child == CurrentItem)
{
- ((IShellController)this).OnFlyoutItemSelected(Items[0]);
+ for (var i = 0; i < Items.Count; i++)
+ {
+ var item = Items[i];
+ if (ValidDefaultShellItem(item))
+ {
+ ((IShellController)this).OnFlyoutItemSelected(item);
+ break;
+ }
+ }
}
}
+ bool ValidDefaultShellItem(Element child) => !(child is MenuShellItem);
+
internal override IEnumerable<Element> ChildrenNotDrawnByThisElement
{
get