Skip to content

Conversation

@Vignesh-SF3580
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue Detail

NavigatingFrom event order is inconsistent across platforms when using PushAsync.

Root Cause

The NavigatingFrom event is currently invoked after the page is pushed.

Description of Change

Moved the NavigatingFrom event to be invoked before pushing the page.

Comment: #28998 (comment)

Reference: 


iOS: https://github.com/dotnet/maui/blob/e838b500c3f62c579d97bcbaeacf321dc1632d2c/src/Controls/src/Core/NavigationPage/NavigationPage.Legacy.cs#L186

Modal Navigation: https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/Platform/ModalNavigationManager/ModalNavigationManager.cs#L268

image

Tested the behavior in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #31520

Screenshots

Before Issue Fix After Issue Fix
31520BeforeFix.mov
31520AfterFix.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Sep 9, 2025
@dotnet-policy-service
Copy link
Contributor

Hey there @@Vignesh-SF3580! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Sep 9, 2025
@jsuarezruiz jsuarezruiz added the area-navigation NavigationPage label Sep 9, 2025
@jsuarezruiz
Copy link
Contributor

jsuarezruiz commented Sep 9, 2025

/azp run

@jsuarezruiz jsuarezruiz self-assigned this Sep 9, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Vignesh-SF3580 Vignesh-SF3580 marked this pull request as ready for review September 10, 2025 05:03
Copilot AI review requested due to automatic review settings September 10, 2025 05:03
@Vignesh-SF3580 Vignesh-SF3580 requested a review from a team as a code owner September 10, 2025 05:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an inconsistency in the NavigatingFrom event timing when using PushAsync navigation on Android and Windows platforms. The NavigatingFrom event was being triggered after the page was pushed to the navigation stack, but it should be triggered before the push operation to maintain consistency with other platforms and navigation methods.

  • Moved the NavigatingFrom event invocation to occur before the page is pushed to the navigation stack
  • Added comprehensive UI tests to validate the correct event ordering
  • Fixed the timing inconsistency across Android and Windows platforms

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Controls/src/Core/NavigationPage/NavigationPage.cs Moved SendNavigating call to occur before PushPage operation in the navigation stack update
src/Controls/tests/TestCases.HostApp/Issues/Issue31520.cs Added UI test page that demonstrates and validates NavigatingFrom event timing relative to Disappearing event
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31520.cs Added NUnit test that verifies NavigatingFrom triggers before Disappearing event during navigation

[Issue(IssueTracker.Github, 31520, "NavigatingFrom is triggered first when using PushAsync", PlatformAffected.Android)]
public class Issue31520 : NavigationPage
{
public static int count = 0;
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

Using a static counter variable can lead to issues if tests run in parallel or if state persists between test runs. Consider using instance variables or resetting the counter in test setup to ensure test isolation.

Copilot uses AI. Check for mistakes.
return Owner.SendHandlerUpdateAsync(animated,
() =>
{
// Move the SendNavigating here so that it's fired prior to the stack being modified
Copy link
Contributor

Choose a reason for hiding this comment

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

Can include in the comment something like:
"This ensures consistent event ordering across all platforms (iOS, Catalyst, Android, Windows)"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz I’ve added the comment as suggested.

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/rebase

@github-actions github-actions bot force-pushed the fix-navigatingPushAsync branch from f86c66e to b86ec9d Compare September 17, 2025 07:12
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen changed the base branch from main to inflight/candidate September 18, 2025 20:22
@PureWeen PureWeen merged commit 8e1b8d0 into dotnet:inflight/candidate Sep 18, 2025
127 of 129 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 18, 2025
…ushAsync (#31536)

* Update NavigationPage.cs

* Added test

* Update NavigationPage.cs

* Update NavigationPage.cs
github-actions bot pushed a commit that referenced this pull request Sep 23, 2025
…ushAsync (#31536)

* Update NavigationPage.cs

* Added test

* Update NavigationPage.cs

* Update NavigationPage.cs
github-actions bot pushed a commit that referenced this pull request Sep 23, 2025
…ushAsync (#31536)

* Update NavigationPage.cs

* Added test

* Update NavigationPage.cs

* Update NavigationPage.cs
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-navigation NavigationPage community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android, Windows] NavigatingFrom event order inconsistent across platforms with PushAsync

3 participants