Skip to content

[Android, Windows] Fixed App.Current.PageDisappearing not raised when a page is popped #28998

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Vignesh-SF3580
Copy link
Contributor

@Vignesh-SF3580 Vignesh-SF3580 commented Apr 15, 2025

Issue Detail

App.Current.PageDisappearing is not raised when a page is popped using PopAsync/PopToRootAsync

Root Cause

The navigation stack was not updated correctly when the Disappearing event was invoked. The page was removed from the stack before the event was triggered. Since the page was already removed, its parent was set to null, and as a result, the Disappearing event was not invoked.

Description of change

Modified the logic to trigger the Disappearing event before removing the page from the stack, which resolves the issue.

Reference

On iOS, Disappearing event is invoked first then the page is removed from the stack.
In PopModalAsync also, Disappearing invoked first then Removed from stack.

Attached is a reference showing the order of events before and after the fix.
image

Issues Fixed

Fixes #14092

Screenshots

Before Issue Fix After Issue Fix
14092Before1.mov
14092After1.mov

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Apr 15, 2025
@Vignesh-SF3580 Vignesh-SF3580 marked this pull request as ready for review April 15, 2025 12:05
@Copilot Copilot AI review requested due to automatic review settings April 15, 2025 12:05
@Vignesh-SF3580 Vignesh-SF3580 requested a review from a team as a code owner April 15, 2025 12:05
Copy link
Contributor

@Copilot 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.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/Controls/src/Core/NavigationPage/NavigationPage.cs:786

  • The change correctly fires the Disappearing event before the page is removed. Please verify that similar navigation flows (e.g., modal pops) have been adjusted consistently to avoid related issues.
Owner.FireDisappearing(currentPage);

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14092.cs:16

  • [nitpick] Consider renaming the test method to 'PageDisappearingEventTriggeredOnPop' to improve clarity and consistency with event naming.
public void PageDisAppearingTriggeredWhenPop()

Copy link
Contributor

@bhavanesh2001 bhavanesh2001 left a comment

Choose a reason for hiding this comment

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

Won’t the same issue happen with PopToRoot too?

return Owner.SendHandlerUpdateAsync(animated,
() =>
{
var lastIndex = NavigationStack.Count - 1;
while (lastIndex > 0)
{
var page = (Page)NavigationStack[lastIndex];
Owner.RemoveFromInnerChildren(page);
lastIndex = NavigationStack.Count - 1;
pagesToRemove.Insert(0, page);
}
Owner.CurrentPage = newPage;
},
() =>
{
Owner.SendNavigating(previousPage);
Owner.FireDisappearing(previousPage);
Owner.FireAppearing(newPage);
},

@Vignesh-SF3580
Copy link
Contributor Author

Won’t the same issue happen with PopToRoot too?

return Owner.SendHandlerUpdateAsync(animated,
() =>
{
var lastIndex = NavigationStack.Count - 1;
while (lastIndex > 0)
{
var page = (Page)NavigationStack[lastIndex];
Owner.RemoveFromInnerChildren(page);
lastIndex = NavigationStack.Count - 1;
pagesToRemove.Insert(0, page);
}
Owner.CurrentPage = newPage;
},
() =>
{
Owner.SendNavigating(previousPage);
Owner.FireDisappearing(previousPage);
Owner.FireAppearing(newPage);
},

@bhavanesh2001 Yes, the same issue also occurs with PopToRoot. I’ve addressed it as well and included the fix in this PR.

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android 🤖 platform/windows 🪟
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App.Current.PageDisappearing is not raised when a page is popped from the navigation stack.
3 participants