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 @@ -70,6 +70,8 @@ void IAppearanceObserver.OnAppearanceChanged(ShellAppearance appearance)
ShellSection _shellSection;
bool _ignorePopCall;

bool _popRequested;

// When setting base.ViewControllers iOS doesn't modify the property right away.
// if you set base.ViewControllers to a new array and then retrieve base.ViewControllers
// iOS will return the previous array until the new array has been processed
Expand Down Expand Up @@ -101,8 +103,13 @@ public ShellSectionRenderer(IShellContext context, Type navigationBarType, Type

[Export("navigationBar:shouldPopItem:")]
[Internals.Preserve(Conditional = true)]
public bool ShouldPopItem(UINavigationBar _, UINavigationItem __) =>
SendPop();
public bool ShouldPopItem(UINavigationBar _, UINavigationItem __)
=> SendPop();

[Export("navigationBar:didPopItem:")]
[Internals.Preserve(Conditional = true)]
bool DidPopItem(UINavigationBar _, UINavigationItem __)
=> _popRequested || SendPop();

internal bool SendPop()
{
Expand Down Expand Up @@ -387,6 +394,7 @@ protected virtual void OnNavigationRequested(object sender, NavigationRequestedE

protected virtual async void OnPopRequested(NavigationRequestedEventArgs e)
{
_popRequested = true;
var page = e.Page;
var animated = e.Animated;

Expand Down Expand Up @@ -427,6 +435,7 @@ async void ProcessPopToRoot()

protected virtual async void OnPopToRootRequested(NavigationRequestedEventArgs e)
{
_popRequested = true;
var animated = e.Animated;
var task = new TaskCompletionSource<bool>();
var pages = _shellSection.Stack.ToList();
Expand Down Expand Up @@ -588,14 +597,15 @@ public override UIViewController[] PopToViewController(UIViewController viewCont
public override void PushViewController(UIViewController viewController, bool animated)
{
_pendingViewControllers = null;
_popRequested = false;
if (IsInMoreTab && ParentViewController is UITabBarController tabBarController)
{
tabBarController.MoreNavigationController.PushViewController(viewController, animated);
}
else
{
base.PushViewController(viewController, animated);
}
}
}

public override UIViewController PopViewController(bool animated)
Expand Down
53 changes: 53 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue23892.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 23892, "Using long-press navigation on back button using shell does not update the shell's current page", PlatformAffected.iOS)]

public class Issue23892 : TestShell
{
protected override void Init()
{
var page = CreateContentPage("Test page");
int onAppearingCount = 0;

Label label = new Label
{
AutomationId = "label",
Text = "This is a test page"
};
page.Content = new StackLayout()
{
label,
new Button
{
AutomationId = "button",
Text = "Click to navigate to detail page",
Command = new Command(()=> Shell.Current.Navigation.PushAsync(new Issue23892Detail()))
}
};

page.Appearing += (s, e) =>
{
label.Text = $"OnAppearing count: {++onAppearingCount}";
};
Routing.RegisterRoute(nameof(Issue23892Detail), typeof(Issue23892Detail));
}

class Issue23892Detail : ContentPage
{
public Issue23892Detail()
{
SetBackButtonBehavior(this, new BackButtonBehavior
{
TextOverride = "Back",
});

Content = new StackLayout
{
Children =
{
new Label { Text = "This is a detail page" }
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if IOS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

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

public override string Issue => "Using long-press navigation on back button using shell does not update the shell's current page";

[Test]
[Category(UITestCategories.Shell)]
public void ShellBackButtonShouldWorkOnLongPress()
{
App.WaitForElement("button");
App.Click("button");
App.LongPress("Back");
var text = App.FindElement("label").GetText();

Assert.That(text, Is.EqualTo("OnAppearing count: 2"));
}
}
}
#endif
Loading