Skip to content
Closed
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 @@ -43,6 +43,10 @@ public TabbedRenderer()
{
this.DisableiOS18ToolbarTabs();
_viewHandlerWrapper = new ViewHandlerDelegator<TabbedPage>(Mapper, CommandMapper, this);
if (MoreNavigationController is not null)
{
MoreNavigationController.Delegate = new MoreTabDelegate(this);
}
}

public override UIViewController SelectedViewController
Expand All @@ -60,6 +64,28 @@ public override UIViewController SelectedViewController
}
}

internal void UpdateCurrentPageForMoreTab()
{
bool isInMoreTab = false;
// Check if the selected tab is in the More tab
if (MoreNavigationController is not null && MoreNavigationController.ViewControllers is not null)
{
foreach (var viewController in MoreNavigationController.ViewControllers)
{
if (viewController == SelectedViewController)
{
isInMoreTab = true;
break;
}
}
}

if (isInMoreTab)
{
UpdateCurrentPage();
}
}

protected TabbedPage Tabbed
{
get { return (TabbedPage)Element; }
Expand Down Expand Up @@ -190,7 +216,7 @@ void OnPagePropertyChanged(object sender, PropertyChangedEventArgs e)
UpdateTabBarItem(page);
}
}

public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection)
{
if (previousTraitCollection.VerticalSizeClass == TraitCollection.VerticalSizeClass)
Expand Down Expand Up @@ -522,6 +548,11 @@ void UpdateChildrenOrderIndex(UIViewController[] viewControllers)

void UpdateCurrentPage()
{
if (SelectedViewController?.Title?.Equals("More", StringComparison.Ordinal) == true)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does checking for "More" also works if the device is set to a language other than English?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Jabbah76 Yes, I tested by changing the device language to a non-English language, and it works as expected.

{
Tabbed.CurrentPage = null;
return;
}
if (Tabbed is TabbedPage tabbed)
{
var count = tabbed.InternalChildren.Count;
Expand Down Expand Up @@ -669,4 +700,24 @@ void IElementHandler.DisconnectHandler()
}
#endregion
}

class MoreTabDelegate : UINavigationControllerDelegate
{
readonly WeakReference<TabbedRenderer> _renderer;

public MoreTabDelegate(TabbedRenderer renderer)
{
_renderer = new WeakReference<TabbedRenderer>(renderer);
}

public override void DidShowViewController(UINavigationController navigationController, UIViewController viewController, bool animated)
{
if (_renderer is not null
&& _renderer.TryGetTarget(out var renderer)
&& !renderer.SelectedViewController?.Title?.Equals("More", StringComparison.Ordinal) == true)
{
renderer.UpdateCurrentPageForMoreTab();
}
}
}
}
39 changes: 39 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue16175.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 16175, "OnNavigatedTo event triggered in More tabs", PlatformAffected.iOS)]

public class Issue16175 : TabbedPage
{
public Issue16175()
{
for (var i = 0; i < 10; i++)
{
var page = new Issue16175Page { Title = $"Tab{i + 1}" };
Children.Add(page);
}
}
}

public class Issue16175Page : ContentPage
{
Label _navigatedToLabel;

public Issue16175Page()
{
_navigatedToLabel = new Label { Text = "NavigatedTo: Not triggered", AutomationId = "navigatedToLabel" };

Content = new VerticalStackLayout
{
Children = { _navigatedToLabel }
};
}

protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
if (Title is not null && Title == "Tab8" && _navigatedToLabel is not null)
{
_navigatedToLabel.Text = "NavigatedTo: Triggered";
}
base.OnNavigatedTo(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_ANDROID // More tab is available in Mac and iOS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue16175 : _IssuesUITest
{
public Issue16175(TestDevice device) : base(device)
{
}
public override string Issue => "OnNavigatedTo event triggered in More tabs";

[Test]
[Category(UITestCategories.TabbedPage)]
public void TabEventsTriggeredInMoreTab()
{
App.TapTab("More");
App.TapTab("Tab8");
var navigatedToLabel = App.WaitForElement("navigatedToLabel");
Assert.That(navigatedToLabel.GetText(), Is.EqualTo("NavigatedTo: Triggered"));
}
}
#endif
Loading