diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs index a3ae0cd48fd4..a69facb7c737 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs @@ -601,6 +601,19 @@ public override void PushViewController(UIViewController viewController, bool an if (IsInMoreTab && ParentViewController is UITabBarController tabBarController) { tabBarController.MoreNavigationController.PushViewController(viewController, animated); + + 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); + } } else { diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue27799.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue27799.cs new file mode 100644 index 000000000000..cd4c9f14363d --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue27799.cs @@ -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 + { + 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++; + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27799.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27799.cs new file mode 100644 index 000000000000..625aed8c512e --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27799.cs @@ -0,0 +1,38 @@ +#if IOS || ANDROID +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) + { + } + + public override string Issue => "[iOS] OnAppearing and OnNavigatedTo does not work when using extended Tabbar"; + + [Test] + [Category(UITestCategories.Shell)] + [Category(UITestCategories.Navigation)] + public void OnAppearingAndOnNavigatedToShouldBeCalles() + { + 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 \ No newline at end of file