Skip to content
Merged
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 @@ -119,15 +119,16 @@ bool DidPopItem(UINavigationBar _, UINavigationItem __)
return SendPop();
}

internal bool SendPop()
internal bool SendPop(UIViewController topViewController = null)
{
// this means the pop is already done, nothing we can do
if (ActiveViewControllers().Length < NavigationBar.Items.Length)
return true;

topViewController ??= TopViewController;
foreach (var tracker in _trackers)
{
if (tracker.Value.ViewController == TopViewController)
if (tracker.Value.ViewController == topViewController)
{
var behavior = Shell.GetEffectiveBackButtonBehavior(tracker.Value.Page);
var command = behavior.GetPropertyIfSet<ICommand>(BackButtonBehavior.CommandProperty, null);
Expand Down Expand Up @@ -611,6 +612,8 @@ public override void PushViewController(UIViewController viewController, bool an
if (IsInMoreTab && ParentViewController is UITabBarController tabBarController)
{
tabBarController.MoreNavigationController.PushViewController(viewController, animated);
viewController.NavigationItem.BackAction = UIAction.Create((e) => SendPop(tabBarController.MoreNavigationController.TopViewController));
HandleMoreNavigationCompletionTasks(viewController);
}
else
{
Expand All @@ -623,12 +626,30 @@ public override UIViewController PopViewController(bool animated)
_pendingViewControllers = null;
if (IsInMoreTab && ParentViewController is UITabBarController tabBarController)
{
return tabBarController.MoreNavigationController.PopViewController(animated);
var viewController = tabBarController.MoreNavigationController.PopViewController(animated);
HandleMoreNavigationCompletionTasks(viewController);
return viewController;
}

return base.PopViewController(animated);
}

private void HandleMoreNavigationCompletionTasks(UIViewController viewController)
{
var tasks = _completionTasks;
var popTask = _popCompletionTask;

if (tasks.TryGetValue(viewController, out var source))
{
source.TrySetResult(true);
tasks.Remove(viewController);
}
else if (popTask != null)
{
popTask.TrySetResult(true);
}
}

UIViewController[] ActiveViewControllers() =>
_pendingViewControllers ?? base.ViewControllers;

Expand Down
74 changes: 74 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27799.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
namespace Maui.Controls.Sample.Issues
{

[Issue(IssueTracker.Github, 27799, "[iOS] OnAppearing and OnNavigatedTo does not work when using extended Tabbar", PlatformAffected.iOS)]

public class Issue27799 : TestShell
Comment on lines +4 to +6
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename is Issue27999.cs but the class name and Issue attribute reference issue #27799. The filename should be Issue27799.cs to match the issue number being tested.

Copilot uses AI. Check for mistakes.
{
private static int _onNavigatedToCount = 0;
private static int _onAppearingCount = 0;

protected override void Init()
{
Routing.RegisterRoute(nameof(Tab6Subpage), typeof(Tab6Subpage));
AddBottomTab("tab1");
AddBottomTab(new Tab2(), "tab2");
AddBottomTab("tab3");
AddBottomTab("tab4");
AddBottomTab("tab5");
AddBottomTab(new Tab6(), "Tab6");
}

class Tab2 : ContentPage
{
Label _onNavigatedToCountLabel;
Label _onAppearingCountLabel;
public Tab2()
{
_onNavigatedToCountLabel = new Label { AutomationId = "OnNavigatedToCountLabel", Text = $"OnNavigatedTo: {_onNavigatedToCount}" };
_onAppearingCountLabel = new Label { AutomationId = "OnAppearingCountLabel", Text = $"OnAppearing: {_onAppearingCount}" };
Content = new StackLayout
{
Children =
{
_onNavigatedToCountLabel,
_onAppearingCountLabel
}
};
}

protected override void OnNavigatedTo(NavigatedToEventArgs e)
{
_onNavigatedToCount++;
_onNavigatedToCountLabel.Text = $"OnNavigatedTo: {_onNavigatedToCount}";
}

protected override void OnAppearing()
{
_onAppearingCount++;
_onAppearingCountLabel.Text = $"OnAppearing: {_onAppearingCount}";
}
}

class Tab6 : ContentPage
{
public Tab6()
{
Content = new Button
{
Text = "Go to subpage6",
AutomationId = "GoToSubpage6Button",
Command = new Command(async () => await Current.GoToAsync(nameof(Tab6Subpage)))
};
}
protected override void OnNavigatedTo(NavigatedToEventArgs e) => _onNavigatedToCount++;
protected override void OnAppearing() => _onAppearingCount++;
}

class Tab6Subpage : ContentPage
{
protected override void OnNavigatedTo(NavigatedToEventArgs e) => _onNavigatedToCount++;
protected override void OnAppearing() => _onAppearingCount++;
}
}
}
72 changes: 72 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27800.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#if ANDROID || IOS
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 27800, "Shell.BackButtonBehavior does not work when using extended Tabbar", PlatformAffected.iOS)]
public class Issue27800 : TestShell
{

protected override void Init()
{
Routing.RegisterRoute(nameof(Tab6DetailPage), typeof(Tab6DetailPage));
AddBottomTab("tab1");
AddBottomTab("tab2");
AddBottomTab("tab3");
AddBottomTab("tab4");
AddBottomTab("tab5");
AddBottomTab(new Tab6(), "tab6");
}

class Tab6 : ContentPage
{
Label _onNavigatedToCountLabel;
Label _onAppearingCountLabel;
int _onNavigatedToCount;
int _onAppearingCount;

public Tab6()
{
_onNavigatedToCountLabel = new Label { AutomationId = "OnNavigatedToCountLabel", Text = $"OnNavigatedTo: {_onNavigatedToCount}" };
_onAppearingCountLabel = new Label { AutomationId = "OnAppearingCountLabel", Text = $"OnAppearing: {_onAppearingCount}" };
Content = new StackLayout
{
Children =
{
_onNavigatedToCountLabel,
_onAppearingCountLabel,
new Button
{
AutomationId = "button",
Text = "Tap to navigate to a detail page",
Command = new Command(() => Shell.Current.GoToAsync(nameof(Tab6DetailPage)))
}
}
};
}

protected override void OnNavigatedTo(NavigatedToEventArgs e)
{
_onNavigatedToCount++;
_onNavigatedToCountLabel.Text = $"OnNavigatedTo: {_onNavigatedToCount}";
}

protected override void OnAppearing()
{
_onAppearingCount++;
_onAppearingCountLabel.Text = $"OnAppearing: {_onAppearingCount}";
}
}


class Tab6DetailPage : ContentPage
{
public Tab6DetailPage()
{
Shell.SetBackButtonBehavior(this, new BackButtonBehavior
{
TextOverride = "Go Back",
Command = new Command(() => Shell.Current.GoToAsync(".."))
});
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#if IOS // Navigation from the more page is iOS specific
using NUnit.Framework;
using NUnit.Framework.Legacy;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue27799 : _IssuesUITest
{
public Issue27799(TestDevice testDevice) : base(testDevice)
Comment on lines +9 to +11
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename is Issue27999.cs but the class name is Issue27799. The class name should match issue #27799, but the filename doesn't follow the naming convention. Either rename the file to Issue27799.cs or change the class name to Issue27799. According to the UI Testing Guidelines, the filename pattern should be IssueXXXXX.cs where XXXXX corresponds to the GitHub issue number, and the class name should match.

Suggested change
public class Issue27799 : _IssuesUITest
{
public Issue27799(TestDevice testDevice) : base(testDevice)
public class Issue27999 : _IssuesUITest
{
public Issue27999(TestDevice testDevice) : base(testDevice)

Copilot uses AI. Check for mistakes.
{
}

public override string Issue => "[iOS] OnAppearing and OnNavigatedTo does not work when using extended Tabbar";

[Test]
[Category(UITestCategories.Shell)]
public void OnAppearingAndOnNavigatedToShouldBeCalled()
{
App.WaitForElement("More");
App.Click("More");
App.WaitForElement("Tab6");
App.Click("Tab6");
App.WaitForElement("GoToSubpage6Button");
App.Click("GoToSubpage6Button");
App.Click("tab2");
App.WaitForElement("OnNavigatedToCountLabel");
var onNavigatedToCountLabel = App.FindElement("OnNavigatedToCountLabel").GetText();
var onAppearingCountLabel = App.FindElement("OnAppearingCountLabel").GetText();

ClassicAssert.AreEqual("OnNavigatedTo: 3", onNavigatedToCountLabel);
ClassicAssert.AreEqual("OnAppearing: 3", onAppearingCountLabel);
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#if IOS // Navigation from the more page is iOS specific
using NUnit.Framework;
using NUnit.Framework.Legacy;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue27800 : _IssuesUITest
{
public Issue27800(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Shell.BackButtonBehavior does not work when using extended Tabbar";

[Test]
[Category(UITestCategories.Shell)]
public void ShellBackButtonBehaviorShouldWorkWithMoreTab()
{
App.WaitForElement("More");
App.Click("More");
App.WaitForElement("tab6");
App.Click("tab6");
App.WaitForElement("button");
App.Click("button");
App.WaitForElement("Go Back");
App.Click("Go Back");
App.WaitForElement("OnNavigatedToCountLabel");
var onNavigatedToCountLabel = App.FindElement("OnNavigatedToCountLabel").GetText();
var onAppearingCountLabel = App.FindElement("OnAppearingCountLabel").GetText();

ClassicAssert.AreEqual("OnNavigatedTo: 2", onNavigatedToCountLabel);
ClassicAssert.AreEqual("OnAppearing: 2", onAppearingCountLabel);
}
}
}
#endif
Loading