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

Fixed Net 8: Page and control Unloaded events firing on iOS when navigating to another page #25852

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

Conversation

NirmalKumarYuvaraj
Copy link
Contributor

@NirmalKumarYuvaraj NirmalKumarYuvaraj commented Nov 14, 2024

Issue Details:

On the iOS platform, the Loaded and Unloaded events of the current page are triggered twice when navigating to another page.

Root Cause:

The MovedToWindow method in the MauiView class is called twice when page navigation occurs with animation enabled. This behavior causes the _movedToWindow event to be repeatedly wired and unwired, which sequentially triggers the Loaded and Unloaded events.

Description of Change:

To resolve the issue, I moved the UnloadedCheck and OnLoadedCheck methods to the UI thread. This change ensures that calls are queued on the UI thread, allowing the Loaded and Unloaded events to trigger correctly once the UIView is attached to a window. Additionally, I removed redundant code for wiring the Loaded and Unloaded events, as the MovedToWindow method will handle these triggers for all MauiView instances upon attachment to and detachment from the window, with the events firing directly from _movedToWindow
Tested the behaviour in the following platforms.

  • Android
  • Windows
  • iOS
  • Mac

Reference

https://stackoverflow.com/questions/34484518/willmovetowindow-is-called-twice

Issues Fixed

Fixes #21916

Screenshots

Before Issue Fix

before.2.mov

After Issue Fix

after.2.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Nov 14, 2024
@NirmalKumarYuvaraj NirmalKumarYuvaraj changed the title Fix included and UI test case added Fixed Net 8: Page and control Unloaded events firing on iOS when navigating to another page Nov 14, 2024
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@NirmalKumarYuvaraj NirmalKumarYuvaraj marked this pull request as ready for review November 14, 2024 12:55
@NirmalKumarYuvaraj NirmalKumarYuvaraj requested a review from a team as a code owner November 14, 2024 12:55
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho
Copy link
Member

/rebase

@rmarinho
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@@ -0,0 +1,28 @@
#if !ANDROID && !MACCATALYST
Copy link
Contributor

Choose a reason for hiding this comment

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

Why avoid Android? Could be nice to test the same behavior in all the platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the Android platform, the Unloaded event of the current page is not triggered when navigating to the next page. As a result, the UI test case for Android has been skipped. Let me know if you have any further concerns.

Android issue link : #26050

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you include a comment and the link to the issue?

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 , here is the link to the issue - #26050

@PureWeen PureWeen added this to the .NET 9 SR2 milestone Nov 24, 2024
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-navigation NavigationPage community ✨ Community Contribution platform/iOS 🍎
Projects
Status: Changes Requested
Development

Successfully merging this pull request may close these issues.

Net 8: Page and control Unloaded events firing on iOS when navigating to another page
5 participants