Skip to content

Commit bd844b4

Browse files
authored
Fix navigation stuck when pushing on hidden tab section in TabBar (#22574)
1 parent bfd3c34 commit bd844b4

File tree

4 files changed

+92
-4
lines changed

4 files changed

+92
-4
lines changed

src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,21 @@ void PushPage(Page page, bool animated, TaskCompletionSource<bool> completionSou
621621
var renderer = (IPlatformViewHandler)page.ToHandler(_shellSection.FindMauiContext());
622622

623623
var tracker = _context.CreatePageRendererTracker();
624-
tracker.ViewController = renderer.ViewController;
624+
var pageViewController = renderer.ViewController!;
625+
tracker.ViewController = pageViewController;
625626
tracker.Page = page;
626627

627628
_trackers[page] = tracker;
628629

629-
if (completionSource != null)
630-
_completionTasks[renderer.ViewController] = completionSource;
630+
var parentTabBar = ParentViewController as UITabBarController;
631+
var showsPresentation = parentTabBar == null || ReferenceEquals(parentTabBar.SelectedViewController, this);
632+
if (completionSource != null && showsPresentation)
633+
_completionTasks[pageViewController] = completionSource;
631634

632-
PushViewController(renderer.ViewController, animated);
635+
PushViewController(pageViewController, animated);
636+
637+
if (completionSource != null && !showsPresentation)
638+
completionSource.TrySetResult(true);
633639
}
634640

635641
async void SendPoppedOnCompletion(Task popTask)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue22570">
5+
<TabBar Route="main"
6+
Title="Tabs">
7+
<ShellContent
8+
Title="Home"
9+
Route="Home">
10+
<ContentPage>
11+
<VerticalStackLayout>
12+
<Button Text="Navigate to a subpage"
13+
AutomationId="button"
14+
Clicked="Button_Clicked"/>
15+
</VerticalStackLayout>
16+
</ContentPage>
17+
</ShellContent>
18+
<ShellContent Title="Foo" Route="Foo">
19+
<ContentPage/>
20+
</ShellContent>
21+
</TabBar>
22+
</Shell>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.Maui.Controls;
2+
using Microsoft.Maui.Controls.Xaml;
3+
4+
namespace Maui.Controls.Sample.Issues
5+
{
6+
[XamlCompilation(XamlCompilationOptions.Compile)]
7+
[Issue(IssueTracker.Github, 22570, "[iOS] Cross TabBar navigation broken", PlatformAffected.iOS)]
8+
public partial class Issue22570 : Shell
9+
{
10+
public Issue22570()
11+
{
12+
InitializeComponent();
13+
Routing.RegisterRoute("Bar22570", typeof(Issue22570Page));
14+
}
15+
16+
void Button_Clicked(object sender, System.EventArgs e)
17+
{
18+
_ = GoToAsync("//main/Foo/Bar22570");
19+
}
20+
21+
public class Issue22570Page : ContentPage
22+
{
23+
public Issue22570Page()
24+
{
25+
Content = new VerticalStackLayout()
26+
{
27+
new Label()
28+
{
29+
Text = "Hello, World!",
30+
AutomationId = "label"
31+
}
32+
};
33+
}
34+
}
35+
}
36+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
public class Issue22570 : _IssuesUITest
8+
{
9+
public Issue22570(TestDevice device)
10+
: base(device)
11+
{ }
12+
13+
public override string Issue => "[iOS] Cross TabBar navigation broken";
14+
15+
[Test]
16+
[Category(UITestCategories.Shell)]
17+
public void Issue22570Test()
18+
{
19+
App.WaitForElement("button");
20+
App.Click("button");
21+
App.WaitForElement("label");
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)