diff --git a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs index 3aae54fa9c74..29f4e3e8f076 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs @@ -241,11 +241,29 @@ public override void ViewDidLoad() Element.PropertyChanged += HandlePropertyChanged; + InteractivePopGestureRecognizer.Delegate = new GestureDelegate(() => _uiRequestedPop = true); + UpdateToolBarVisible(); UpdateBackgroundColor(); Current = navPage.CurrentPage; } + class GestureDelegate : UIGestureRecognizerDelegate + { + readonly Func _shouldPop; + + public GestureDelegate(Func shouldPop) + { + _shouldPop = shouldPop; + } + + public override bool ShouldBegin(UIGestureRecognizer recognizer) + { + _shouldPop(); + return true; + } + } + protected override void Dispose(bool disposing) { if (_disposed) diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue27143.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue27143.cs new file mode 100644 index 000000000000..27a9597c780d --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue27143.cs @@ -0,0 +1,50 @@ +namespace Maui.Controls.Sample.Issues +{ + + [Issue(IssueTracker.Github, 27143, "Not trigger OnNavigatedTo method when hide the navi bar and using swipe", PlatformAffected.iOS)] + public class Issue27143NavigationPage : NavigationPage + { + public Issue27143NavigationPage() : base(new Issue27143()) { } + + class Issue27143 : ContentPage + { + int _navigatedToEventTriggersCount; + + Label _label; + + public Issue27143() + { + ContentPage subpage = new ContentPage() + { + Content = new Label() + { + Text = "Hello from the other side!", + } + }; + + SetHasNavigationBar(this, false); + + _label = new Label() + { + AutomationId = "navigatedToEventTriggersCountLabel", + }; + + Content = new VerticalStackLayout() + { + new Button() + { + Text = "Click to navigate", + AutomationId = "button", + Command = new Command(() => Window!.Page!.Navigation.PushAsync(subpage, false)) + }, + _label + }; + } + + protected override void OnNavigatedTo(NavigatedToEventArgs args) + { + _label.Text = $"NavigatedTo event triggers count: {++_navigatedToEventTriggersCount}"; + } + } + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27143.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27143.cs new file mode 100644 index 000000000000..8cf0d61a47fe --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27143.cs @@ -0,0 +1,27 @@ +#if IOS && TEST_FAILS_ON_IOS // Remove it once you find a way to perform swipe to navigate back +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues +{ + public class Issue27143 : _IssuesUITest + { + public Issue27143(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "Not trigger OnNavigatedTo method when hide the navi bar and using swipe"; + + [Test] + [Category(UITestCategories.Navigation)] + public void OnNavigatedToShouldTrigger() + { + App.WaitForElement("button"); + App.Click("button"); + // Find a way to perform swipe to navigate back + App.WaitForElement("NavigatedTo event triggers count: 2"); + } + } +} +#endif \ No newline at end of file