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

Fix iOS Navigation #3467

Merged
merged 1 commit into from
Nov 19, 2021
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 @@ -154,6 +154,11 @@ async void SendHandlerUpdate(bool animated)
Action firePostNavigatingEvents,
Action fireNavigatedEvents)
{
if (!_setForMaui || this.IsShimmed())
{
return;
}

try
{
processStackChanges?.Invoke();
Expand Down
13 changes: 7 additions & 6 deletions src/Controls/src/Core/NavigationPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,24 @@ public partial class NavigationPage : Page, IPageContainer<Page>, IBarElement, I

partial void Init();

public NavigationPage() : this(
#if WINDOWS || ANDROID
true
const bool UseMauiHandler = true;
#else
false
const bool UseMauiHandler = false;
#endif
)

bool _setForMaui;
public NavigationPage() : this(UseMauiHandler)
{
}

public NavigationPage(Page root) : this()
public NavigationPage(Page root) : this(UseMauiHandler, root)
{
PushPage(root);
}

internal NavigationPage(bool setforMaui, Page root = null)
{
_setForMaui = setforMaui;
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<NavigationPage>>(() => new PlatformConfigurationRegistry<NavigationPage>(this));

if (setforMaui)
Expand Down
35 changes: 35 additions & 0 deletions src/Controls/tests/Core.UnitTests/NavigationUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,41 @@ namespace Microsoft.Maui.Controls.Core.UnitTests
[TestFixture]
public class NavigationUnitTest : BaseTestFixture
{
[TestCase(false)]
[TestCase(true)]
public async Task HandlerUpdatesDontFireForLegacy(bool withPage)
{
TestNavigationPage nav =
new TestNavigationPage(false, (withPage) ? new ContentPage() : null);

var handler = new TestNavigationHandler();
(nav as IView).Handler = handler;


Assert.IsNull(nav.CurrentNavigationTask);
Assert.IsNull(handler.CurrentNavigationRequest);
}

[TestCase(false)]
[TestCase(true)]
public async Task HandlerUpdatesFireWithStartingPage(bool withPage)
{
TestNavigationPage nav =
new TestNavigationPage(true, (withPage) ? new ContentPage() : null);

var handler = new TestNavigationHandler();
(nav as IView).Handler = handler;

if (!withPage)
{
Assert.IsNull(nav.CurrentNavigationTask);
}
else
{
Assert.IsNotNull(nav.CurrentNavigationTask);
}
}

[TestCase(false)]
[TestCase(true)]
public async Task TestNavigationImplPush(bool useMaui)
Expand Down