Skip to content

Commit

Permalink
[Windows] - Fix for Shell Section Visibility changes not reflected un…
Browse files Browse the repository at this point in the history
…til Tab switch (dotnet#26130)

* Shell section visibility fix.

* Added test case.

* Windows ShellSectionHandler changes.

* Windows test script changes

* snapshot for Windows
  • Loading branch information
Tamilarasan-Paranthaman authored Nov 28, 2024
1 parent b7069ed commit 37a2d9d
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void OnNavigationTabChanged(NavigationView sender, NavigationViewSelecti
}
}

void MapMenuItems()
internal void MapMenuItems()
{
IShellItemController shellItemController = VirtualView;
var items = new List<BaseShellItem>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using Microsoft.Maui.Controls.Internals;
using WFrame = Microsoft.UI.Xaml.Controls.Frame;
Expand Down Expand Up @@ -54,6 +55,8 @@ public override void SetVirtualView(Maui.IElement view)
{
((IShellSectionController)_shellSection).NavigationRequested -= OnNavigationRequested;

((IShellSectionController)_shellSection).ItemsCollectionChanged -= OnItemsCollectionChanged;

if (_lastShell?.Target is IShellController shell)
{
shell.RemoveAppearanceObserver(this);
Expand Down Expand Up @@ -82,6 +85,8 @@ public override void SetVirtualView(Maui.IElement view)
{
((IShellSectionController)_shellSection).NavigationRequested += OnNavigationRequested;

((IShellSectionController)_shellSection).ItemsCollectionChanged += OnItemsCollectionChanged;

var shell = _shellSection.FindParentOfType<Shell>() as IShellController;
if (shell != null)
{
Expand All @@ -96,6 +101,17 @@ void OnNavigationRequested(object? sender, NavigationRequestedEventArgs e)
SyncNavigationStack(e.Animated, e);
}

void OnItemsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
if (_shellSection is null)
return;

if (_shellSection.Parent is ShellItem shellItem && shellItem.Handler is ShellItemHandler shellItemHandler)
{
shellItemHandler.MapMenuItems();
}
}

void SyncNavigationStack(bool animated, NavigationRequestedEventArgs? e)
{
// Current Item might transition to null while visibility is adjusting on shell
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25913.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 25913, "Top Tab Visibility Changes Not Reflected Until Tab Switch", PlatformAffected.UWP)]
public partial class Issue25913 : Shell
{
public Issue25913()
{
InitializeShell();
}

private void InitializeShell()
{
var tabBar = new TabBar();

var tab1 = new Tab { Title = "Tab 1" };
var topTab1Content = new ContentPage
{
Title = "TopTab1",
Content = CreateControlPanel()
};

var topTab2Content = new ContentPage
{
Title = "TopTab2",
Content = CreateControlPanel()
};

var topTab3Content = new ContentPage
{
Title = "TopTab3",
Content = CreateControlPanel()
};

tab1.Items.Add(topTab1Content);
tab1.Items.Add(topTab2Content);
tab1.Items.Add(topTab3Content);

var tab2 = new Tab
{
Title = "Tab 2",
Items =
{
new ShellContent
{
Content = new ContentPage
{
Content = new Label { Text = "Tab 2 Content" }
}
}
}
};

var tab3 = new Tab
{
Title = "Tab 3",
Items =
{
new ShellContent
{
Content = new ContentPage
{
Content = new Label { Text = "Tab 3 Content" }
}
}
}
};

tabBar.Items.Add(tab1);
tabBar.Items.Add(tab2);
tabBar.Items.Add(tab3);

Items.Add(tabBar);
}

private View CreateControlPanel()
{
return new ScrollView
{
Content = new StackLayout
{
Spacing = 10,
Padding = new Thickness(20),
Children =
{
new Button
{
Text = "Hide Top Tab 3",
Command = new Command(() =>
{
Items[0].Items[0].Items[2].IsVisible = false;
}),
AutomationId = "HideTop3"
}
}
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue25913 : _IssuesUITest
{
public override string Issue => "Top Tab Visibility Changes Not Reflected Until Tab Switch";

public Issue25913(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.Shell)]
public void DynamicTabSectionVisibility()
{
App.WaitForElement("HideTop3");
App.Tap("HideTop3");
#if WINDOWS
App.Tap("Tab 1");
#endif
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 37a2d9d

Please sign in to comment.