Skip to content

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

Merged
PureWeen merged 6 commits intodotnet:mainfrom
NirmalKumarYuvaraj:fix-21916
Dec 17, 2024
Merged

Fixed Net 8: Page and control Unloaded events firing on iOS when navigating to another page#25852
PureWeen merged 6 commits intodotnet:mainfrom
NirmalKumarYuvaraj:fix-21916

Conversation

@NirmalKumarYuvaraj
Copy link
Copy Markdown
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
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

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
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho
Copy link
Copy Markdown
Member

/rebase

@rmarinho
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@@ -0,0 +1,28 @@
#if !ANDROID && !MACCATALYST
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@PureWeen
Copy link
Copy Markdown
Member

PureWeen commented Dec 4, 2024

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@sheiksyedm sheiksyedm added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Dec 5, 2024
@PureWeen PureWeen modified the milestones: .NET 9 SR2, .NET 9 SR3 Dec 6, 2024
@PureWeen
Copy link
Copy Markdown
Member

/rebase

@PureWeen
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen dismissed jsuarezruiz’s stale review December 16, 2024 20:44

Changes Addressed

@PureWeen
Copy link
Copy Markdown
Member

PureWeen commented Dec 16, 2024

I tried a few different ways to fix this. I'm never a fan of fixing something by just invoking back to the main thread but I'm not really sure how else to resolve this currently.

One thought I had was that if we just stopped firing unloaded when the view is still part of the xplat tree that would be one way where the number of MovedToWindows wouldn't matter.

i created an issue here for .NET 10 that we can look at
#26659

which might generally make loaded/unloaded operate more consistently between platforms

@PureWeen
Copy link
Copy Markdown
Member

  • DelayedIsRefreshingAndCommandTest_SwipeDown is an unrelated failure

@PureWeen PureWeen merged commit 7291b48 into dotnet:main Dec 17, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 17, 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 platform/ios

Projects

Status: Done

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

6 participants