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] Trigger OnNavigatedTo method when hide the nav bar and using swipe gesture #27186

Open
wants to merge 2 commits 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 @@ -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<bool> _shouldPop;

public GestureDelegate(Func<bool> shouldPop)
{
_shouldPop = shouldPop;
}

public override bool ShouldBegin(UIGestureRecognizer recognizer)
{
_shouldPop();
return true;
}
}

protected override void Dispose(bool disposing)
{
if (_disposed)
Expand Down
50 changes: 50 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27143.cs
Original file line number Diff line number Diff line change
@@ -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}";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

@kubaflo kubaflo Jan 17, 2025

Choose a reason for hiding this comment

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

@jsuarezruiz do you have some idea of how we can do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @anandhan-rajagopal maybe you can help here :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think App.SwipeRightToLeft should the expected gesture.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've already tried, but it doesn't work :/

App.WaitForElement("NavigatedTo event triggers count: 2");
}
}
}
#endif
Loading