Repository navigation
[Android] Fix immediate modal pop leaving dialog visible after non-animated push - #40135
Conversation
<!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [ ] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change <!-- Enter description of the fix in this section --> <!-- maui-release-state:production:11.0.1xx-sr2 --> Advance canonical **`eng/release-rollover.json`** from SR1 to SR2 after verified staging, reviewed normalization and next-lane preparation. Staged source: `01c74ef93c991830e310a77ec808b51b29bcac1f`. Next candidate: `candidate/11.0.1xx-sr2`. Next inflight: `inflight/11.0.1xx-sr3`. No real release branch or servicing review is required for this state update. Independently, the publication workflow opens a servicing PR against staging; after reviewing it and using Create a merge commit, a maintainer manually cuts the real release at that exact merge. Staging alone never authorizes signing. Only `currentSr` changes. `nightlyMode` remains **legacy**; SDK, package metadata, branch roles, release contents and access rules are unchanged. **Review and required CI are mandatory. Automation never updates the default branch, approves, retargets or merges this PR.** If nightlyMode is already versioned, advancing currentSr also selects the following inflight lane. Before merging, verify that exact lane has its protections, internal mirror, schedule, signed artifacts and existing feed/channel wiring deployed. The first legacy-to-versioned switch is a separate owner-reviewed state change after that deployment evidence exists; this PR does not guess or certify it. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> N/A - staged release configuration. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Wait for the modal page to load and the fragment to resume before completing presentation, so an immediate pop dismisses the native dialog. Add repeated Shell and NavigationPage regression coverage with animated and non-animated pops. Relates to dotnet#40134.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40135Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40135" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
The native Android lifecycle-timing changes require device validation across Loaded/resume orderings and animated/non-animated pops, but the new device tests were not executed.
No open issues 🎉
What changed in this PR
Fixes #40134 by tightening Android modal presentation readiness so an immediate pop after a non-animated push can dismiss the native dialog rather than leaving it visible.
Changes:
- Wait for both the modal page to load and the fragment to resume before completing normal presentation.
- Remove the
Loadedsubscription when presentation completes or the dialog is dismissed. - Add regression coverage for Shell and NavigationPage roots, animated and non-animated pops, and repeated push/pop sequences.
| File | Description |
|---|---|
src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.Android.cs |
Tests readiness, logical stack cleanup, and native dialog dismissal after immediate pops. |
src/Controls/src/Core/Platform/ModalNavigationManager/ModalNavigationManager.Android.cs |
Coordinates loaded/resumed readiness and cleans up the new event subscription. |
Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Expert Review — 0 findings
Reviewed commit cf4988f.
PR Test Gate
🧪 Gate analysis — click to expand✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence. 📱 Device tests
Execution log excerptsWithout fix With fix PR head: cf4988f6. Without-fix baseline: 13832fce. |
64dd3c3
into
dotnet:candidate/11.0.1xx-sr2
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR #32479](#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [#33363](#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…imated push (dotnet#40135) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Issue details Issue reports that immediately popping an Android modal after a non-animated push removes the page from `Navigation.ModalStack`, but leaves its native `ModalFragment` dialog on screen: ```csharp await Navigation.PushModalAsync(new ContentPage { BackgroundColor = Colors.Yellow }, animated: false); await Navigation.PopModalAsync(animated: false); ``` Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in **10.0.20**, failure in **10.0.30**, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load. The immediate push/pop sequence was reproduced in the Sandbox sample on **Android 15/API 35**: before the fix, `Loaded at pop: False; stack: 0; dialogs: 1`. ### Root cause `ModalFragment.OnResume` can run before the modal page's platform view is attached and `Loaded` has fired. Previously, it unconditionally raised `PresentationCompleted`, allowing `PushModalAsync(animated: false)` to return before the modal was ready for an immediate native pop. The subsequent `PopModalAsync` checks `IsModalReady`. When the current platform page is not loaded, it skips `PopModalPlatformAsync` and defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in `_platformModalPages`. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed. ### Regression reason The **likely introducing change** is [PR dotnet#32479](dotnet#32479), which fixed a related hang involving `Task.Yield()` by making non-animated pushes await a new `PresentationCompleted` event. That event was raised synchronously from `OnResume`, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window. Release-source tracing supports this attribution: - The Android modal-manager source in **10.0.20** exactly matches the parent of the [shipped change `5214279`](dotnet@5214279). - The source in **10.0.30** exactly matches both the original PR merge and that shipped change, integrated through [dotnet#33363](dotnet#33363). - The shared modal-manager source is identical between those releases, locating the relevant behavioral difference in Android presentation timing. This is **likely**, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect. ### Fix details In `ModalNavigationManager.Android.cs`, complete presentation only when **both** the page is loaded and the fragment is resumed: - Subscribe to the modal page's `Loaded` event when constructing the fragment. - If `Loaded` happens first, `OnResume` completes presentation only when `IsLoaded` is true. - If resume happens first, the `Loaded` handler completes presentation only when `IsResumed` is true. - Unsubscribe `Loaded` when presentation completes or the dialog is dismissed. - Preserve the existing early-start/destroy completion safeguards. This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes dotnet#40134 <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
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 details
Issue reports that immediately popping an Android modal after a non-animated push removes the page from
Navigation.ModalStack, but leaves its nativeModalFragmentdialog on screen:Expected: the modal closes and the previous page becomes visible. Actual: the logical modal stack is empty, but a full-screen native dialog remains, leaving logical and native navigation out of sync. The author reports working behavior in 10.0.20, failure in 10.0.30, and continued failure in 10.0.40, 10.0.110 and 10.0.130. Animated pushes are not affected by the reported reproduction because the animation gives the page time to load.
The immediate push/pop sequence was reproduced in the Sandbox sample on Android 15/API 35: before the fix,
Loaded at pop: False; stack: 0; dialogs: 1.Root cause
ModalFragment.OnResumecan run before the modal page's platform view is attached andLoadedhas fired. Previously, it unconditionally raisedPresentationCompleted, allowingPushModalAsync(animated: false)to return before the modal was ready for an immediate native pop.The subsequent
PopModalAsyncchecksIsModalReady. When the current platform page is not loaded, it skipsPopModalPlatformAsyncand defers stack synchronization, but still removes the modal's logical parent and disconnects its handler. The native modal remains in_platformModalPages. Deferred synchronization then waits for that same modal to have a handler and loaded platform view, a condition that cannot recover after disconnection. Consequently, the native dialog is never dismissed.Regression reason
The likely introducing change is PR #32479, which fixed a related hang involving
Task.Yield()by making non-animated pushes await a newPresentationCompletedevent. That event was raised synchronously fromOnResume, which is not sufficient proof that the modal page is loaded. An awaiting immediate pop can therefore continue inside this lifecycle timing window.Release-source tracing supports this attribution:
5214279.This is likely, not confirmed introduction: no same-environment runtime comparison of the candidate and its parent was performed. The release histories diverge, so the version comparison was not treated as a linear bisect.
Fix details
In
ModalNavigationManager.Android.cs, complete presentation only when both the page is loaded and the fragment is resumed:Loadedevent when constructing the fragment.Loadedhappens first,OnResumecompletes presentation only whenIsLoadedis true.Loadedhandler completes presentation only whenIsResumedis true.Loadedwhen presentation completes or the dialog is dismissed.This strengthens the presentation-readiness guarantee without adding delays or changing shared modal-stack cleanup. No public API changes are introduced, and other platform implementations are unchanged.
Issues Fixed
Fixes #40134