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

[iOS][Shell][More Tab] Navigation from the 'More' tab - improvements #27932

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -111,15 +111,16 @@ public bool ShouldPopItem(UINavigationBar _, UINavigationItem __)
bool DidPopItem(UINavigationBar _, UINavigationItem __)
=> _popRequested || 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.GetBackButtonBehavior(tracker.Value.Page);
var command = behavior.GetPropertyIfSet<ICommand>(BackButtonBehavior.CommandProperty, null);
Expand Down Expand Up @@ -601,6 +602,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 @@ -613,12 +616,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
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
74 changes: 74 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27999.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
{
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++;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

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)]
[Category(UITestCategories.Navigation)]
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Loading