dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.26k stars 1.76k forks source link

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

Open NirmalKumarYuvaraj opened 1 week ago

NirmalKumarYuvaraj commented 1 week ago

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.

https://github.com/user-attachments/assets/694ce1cb-fbfc-458c-bd66-0b2dafb26594

After Issue Fix

https://github.com/user-attachments/assets/a2878184-c90b-4698-b527-3367723e88fc

jsuarezruiz commented 1 week ago

/azp run

azure-pipelines[bot] commented 1 week ago
Azure Pipelines successfully started running 3 pipeline(s).
jsuarezruiz commented 1 week ago

/azp run

azure-pipelines[bot] commented 1 week ago
Azure Pipelines successfully started running 3 pipeline(s).
rmarinho commented 1 day ago

/rebase

rmarinho commented 1 day ago

/azp run

azure-pipelines[bot] commented 1 day ago
Azure Pipelines successfully started running 3 pipeline(s).