Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Shell Tab is still visible after set Tab.IsVisible to false #24999

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,13 @@ protected override void OnDisplayedPageChanged(Page newPage, Page oldPage)
oldPage.PropertyChanged -= OnDisplayedElementPropertyChanged;

if (newPage is not null)
{
newPage.PropertyChanged += OnDisplayedElementPropertyChanged;
if (oldPage is null)
{
_menuSetup = false;
}
}

if (newPage is not null && !_menuSetup)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ void GoTo(ShellSection shellSection)
if (shellSection == null || _currentSection == shellSection)
return;
var renderer = RendererForShellContent(shellSection);
if (renderer?.ViewController != SelectedViewController)

if (renderer == null)
return;

if (renderer.ViewController != SelectedViewController)
SelectedViewController = renderer.ViewController;
CurrentRenderer = renderer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void OnCurrentShellSectionPropertyChanged(object? sender, System.ComponentModel.
if (_mainLevelTabs == null)
return;

var currentItem = VirtualView.CurrentItem.CurrentItem;
var currentItem = VirtualView.CurrentItem?.CurrentItem;
NavigationViewItemViewModel? navigationViewItemViewModel = null;

foreach (var item in _mainLevelTabs)
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Shell/ShellItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void OnVisibleChildRemoved(Element child)
if (CurrentItem == child)
{
if (ShellItemController.GetItems().Count == 0)
ClearValue(CurrentItemProperty, specificity: SetterSpecificity.FromHandler);
ClearValue(CurrentItemProperty);
else
SetValueFromRenderer(CurrentItemProperty, ShellItemController.GetItems()[0]);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue8788.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue8788"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
Shell.FlyoutBehavior="Locked"
Shell.FlyoutWidth="200">

<MenuItem x:Name="MenuItem" Text="Click to hide Tab1" Clicked="MenuItem_Clicked" AutomationId="FirstButton" />

<TabBar>
<Tab x:Name="Tab1" AutomationId="Tab1" Title="Tab 1">
<ShellContent Title="Tab 1" ContentTemplate="{DataTemplate local:MainTabPage}" Route="MainPage" />
</Tab>

<Tab x:Name="Tab2" AutomationId="Tab2" Title="Tab 2" IsVisible="false">
<ShellContent Title="Tab 2" ContentTemplate="{DataTemplate local:SecondTabPage}" Route="Tab2Page" />
</Tab>

<Tab x:Name="Tab3" Title="Tab 3" AutomationId="Tab3" IsVisible="false">
<ShellContent Title="Tab 3" ContentTemplate="{DataTemplate local:ThirdTabPage}" Route="Tab3Page" />
</Tab>
</TabBar>

</Shell>
81 changes: 81 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue8788.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 8788, "Shell Tab is still visible after set Tab.IsVisible to false", PlatformAffected.Android)]
public partial class Issue8788 : Shell
{
public Issue8788()
{
InitializeComponent();
}

private void MenuItem_Clicked(object sender, EventArgs e)
{
#if ANDROID
Tab2.IsVisible = true;
Tab3.IsVisible = true;
Tab1.IsVisible = false;
#else
Tab1.IsVisible = false;
Tab2.IsVisible = true;
Tab3.IsVisible = true;
#endif
}
}

public partial class MainTabPage : ContentPage
{
public MainTabPage()
{
Content = new VerticalStackLayout()
{
new Label(){
Text = "Page Loaded in first Tab",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
TextDecorations = TextDecorations.Underline,

},
};
}
}

public partial class SecondTabPage : ContentPage
{
public SecondTabPage()
{
Content = new VerticalStackLayout()
{
new Label(){
Text = "Page Loaded in Second Tab",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
TextDecorations = TextDecorations.Underline,

},
};
}
}
public partial class ThirdTabPage : ContentPage
{
public ThirdTabPage()
{
Content = new VerticalStackLayout()
{
new Label(){
Text = "Page Loaded in Third Tab",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
TextDecorations = TextDecorations.Underline,

},
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if !MACCATALYST
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
internal class Issue8788 : _IssuesUITest
{
public Issue8788(TestDevice device) : base(device) { }

public override string Issue => "Shell Tab is still visible after set Tab.IsVisible to false";

[Test]
[Category(UITestCategories.Shell)]
public void ShellTabItemsShouldUpdateForDynamicChangesInVisibility()
{
#if WINDOWS
App.TapCoordinates(100, 57);
#else
App.WaitForElement("FirstButton");
App.Tap("FirstButton");
#endif
VerifyScreenshot();
}
}
}
#endif
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.