Skip to content
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
10 changes: 7 additions & 3 deletions src/Controls/src/Core/Shell/ShellSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,13 @@ protected virtual async Task OnPopToRootAsync(bool animated)
RequestType = NavigationRequestType.PopToRoot
};

InvokeNavigationRequest(args);
PresentedPageDisappearing();
var oldStack = _navStack;
_navStack = new List<Page> { null };

PresentedPageAppearing();
InvokeNavigationRequest(args);

if (args.Task != null)
await args.Task;

Expand All @@ -856,11 +859,12 @@ protected virtual async Task OnPopToRootAsync(bool animated)

for (int i = 1; i < oldStack.Count; i++)
{
oldStack[i].SendDisappearing();
// Send disappearing only to intermediate pages (top page already handled by PresentedPageDisappearing)
if (i < oldStack.Count - 1)
oldStack[i].SendDisappearing();
RemovePage(oldStack[i]);
}

PresentedPageAppearing();
}

protected virtual Task OnPushAsync(Page page, bool animated)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
160 changes: 160 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue33351.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 33351, "Changing Shell Tab Visibility when navigating back multiple pages ignores Shell Tab Visibility", PlatformAffected.All)]
public class Issue33351 : Shell
{
public Issue33351()
{
Routing.RegisterRoute("Issue33351Page1", typeof(Issue33351Page1));
Routing.RegisterRoute("Issue33351Page2", typeof(Issue33351Page2));

var tabBar = new TabBar
{
Items =
{
new MyTab
{
Title = "Tab 1",
ContentTemplate = new DataTemplate(() => new Issue33351MainPage())
},
new ShellContent
{
Title = "Tab 2",
ContentTemplate = new DataTemplate(() => new Issue33351SecondTabPage())
}
}
};

Items.Add(tabBar);
}

class MyTab : ShellContent
{
protected override void OnAppearing()
{
base.OnAppearing();

if (this.Parent != null)
Shell.SetTabBarIsVisible(this.Parent, true);

Shell.Current.Navigating -= OnShellNavigating;
Shell.Current.Navigating += OnShellNavigating;
}

void OnShellNavigating(object sender, ShellNavigatingEventArgs e)
{
if (this.Parent != null)
Shell.SetTabBarIsVisible(this.Parent, false);
}
}

class Issue33351MainPage : ContentPage
{
public Issue33351MainPage()
{
Title = "Main Page";
AutomationId = "RootPage";

var statusLabel = new Label
{
AutomationId = "TabBarVisibleLabel",
Text = "Tab Bar Visible"
};

var navigateButton = new Button
{
AutomationId = "PushPage1Button",
Text = "Go to Page 1",
HorizontalOptions = LayoutOptions.Fill
};

navigateButton.Clicked += async (s, e) =>
{
await Shell.Current.GoToAsync("Issue33351Page1");
};

Content = new VerticalStackLayout
{
Padding = new Thickness(20),
Spacing = 20,
Children = { statusLabel, navigateButton }
};
}
}

class Issue33351Page1 : ContentPage
{
public Issue33351Page1()
{
Title = "Page 1";

var statusLabel = new Label
{
AutomationId = "TabBarHiddenLabel",
Text = "Tab Bar Hidden"
};

var navigateButton = new Button
{
AutomationId = "PushPage2Button",
Text = "Go to Page 2",
HorizontalOptions = LayoutOptions.Fill
};

navigateButton.Clicked += async (s, e) =>
{
await Shell.Current.GoToAsync("Issue33351Page2");
};

Content = new VerticalStackLayout
{
Padding = new Thickness(20),
Spacing = 20,
Children = { statusLabel, navigateButton }
};
}
}

class Issue33351Page2 : ContentPage
{
public Issue33351Page2()
{
Title = "Page 2";
AutomationId = "Page2";

var statusLabel = new Label
{
AutomationId = "TabBarHiddenLabel2",
Text = "Tab Bar Hidden"
};

var popToRootButton = new Button
{
AutomationId = "PopToRootButton",
Text = "Go Back (../..)",
HorizontalOptions = LayoutOptions.Fill
};

popToRootButton.Clicked += async (s, e) =>
{
await Shell.Current.GoToAsync("../..");
};

Content = new VerticalStackLayout
{
Padding = new Thickness(20),
Spacing = 20,
Children = { statusLabel, popToRootButton }
};
}
}

class Issue33351SecondTabPage : ContentPage
{
public Issue33351SecondTabPage()
{
Title = "Tab 2";
Content = new Label { Text = "Tab 2" };
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue33351 : _IssuesUITest
{
public Issue33351(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Changing Shell Tab Visibility when navigating back multiple pages ignores Shell Tab Visibility";

[Test]
[Category(UITestCategories.Shell)]
public void TabBarVisibilityAfterMultiLevelPopToRoot()
{
App.WaitForElement("RootPage");
App.WaitForElement("TabBarVisibleLabel");

App.Tap("PushPage1Button");
App.WaitForElement("TabBarHiddenLabel");

App.Tap("PushPage2Button");
App.WaitForElement("Page2");
App.WaitForElement("TabBarHiddenLabel2");

App.Tap("PopToRootButton");

App.WaitForElement("RootPage");
App.WaitForElement("TabBarVisibleLabel");

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.
Loading