Skip to content

[Android]Fix Navigation stops working when changing Window[0].Page from Shell - #38159

Merged
kubaflo merged 8 commits into
dotnet:inflight/currentfrom
devanathan-vaithiyanathan:fix-38026
Sep 4, 2026
Merged

kubaflo merged 8 commits into
dotnet:inflight/currentfrom
devanathan-vaithiyanathan:fix-38026

Conversation

@devanathan-vaithiyanathan

Copy link
Copy Markdown
Contributor

Issue Details

On Android 16, replacing Window.Page from Shell to NavigationPage leaves Shell’s old DrawerLayout back callback registered. This stale callback intercepts Android back navigation even though Shell is no longer visible.

Description of Change

Before replacing Window.Page, the fix:

  • Detects an outgoing Shell. Closes its flyout if open.
  • Locks the DrawerLayout closed to release its back callback.
  • Refreshes Android’s back-navigation state after installing the new page.

This restores back navigation after switching from Shell to NavigationPage.

Issues Fixed

Fixes #38026

Tested the behavior in the following platforms.

  • Android
  • Windows
  • iOS
  • Mac
Before After
Android
Before.mov
Android
After.mov

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38159

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38159"

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Sep 3, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Sep 3, 2026

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI Review Summary

@devanathan-vaithiyanathan — new AI review results are available based on commit 1ee5535.

Gate Partial Confidence Low Platform Android


🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix

Gate Result: ❌ FAILED

Platform: ANDROID · Base: main · Merge base: 7a2ed62f

🩺 Test does not reproduce the bug — ran the same in both states (PASS without fix, PASS with fix). The repro test is not exercising the issue. Strengthen the test before reviewing the fix.

Test Without Fix (expect FAIL) With Fix (expect PASS)
🖥️ Issue38026 Issue38026 ❌ PASS — 2845s ✅ PASS — 586s
🔴 Without fix — 🖥️ Issue38026: PASS ❌ · 2845s

(no coded error found; showing last 1200 chars)

t execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.18]   Discovering: Controls.TestCases.Android.Tests
[xUnit.net 00:00:00.63]   Discovered:  Controls.TestCases.Android.Tests
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in /home/vsts/work/1/s/artifacts/bin/Controls.TestCases.Android.Tests/Debug/net10.0/Controls.TestCases.Android.Tests.dll
   NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 09/03/2026 15:04:19 FixtureSetup for Issue38026(Android)
>>>>> 09/03/2026 15:04:22 BackWorksAfterReplacingShellWithNavigationPage Start
>>>>> 09/03/2026 15:04:33 BackWorksAfterReplacingShellWithNavigationPage Stop
  Passed BackWorksAfterReplacingShellWithNavigationPage [20 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /home/vsts/work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue38026.trx
Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 9.4666 Minutes
>>> TRX_RESULT_FILE: /home/vsts/work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue38026.trx
🟢 With fix — 🖥️ Issue38026: PASS ✅ · 586s

(no coded error found; showing last 1200 chars)

 execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.13]   Discovering: Controls.TestCases.Android.Tests
[xUnit.net 00:00:00.51]   Discovered:  Controls.TestCases.Android.Tests
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in /home/vsts/work/1/s/artifacts/bin/Controls.TestCases.Android.Tests/Debug/net10.0/Controls.TestCases.Android.Tests.dll
   NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 09/03/2026 15:35:50 FixtureSetup for Issue38026(Android)
>>>>> 09/03/2026 15:35:52 BackWorksAfterReplacingShellWithNavigationPage Start
>>>>> 09/03/2026 15:36:03 BackWorksAfterReplacingShellWithNavigationPage Stop
  Passed BackWorksAfterReplacingShellWithNavigationPage [12 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /home/vsts/work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue38026.trx
Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 27.6111 Seconds
>>> TRX_RESULT_FILE: /home/vsts/work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue38026.trx

⚠️ Failure Details

  • ❌ Issue38026 PASSED without fix (should fail) — tests don't catch the bug
📁 Fix files reverted (3 files)
  • src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs
  • src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellRenderer.cs
  • src/Controls/src/Core/Window/Window.cs

📋 Pre-Flight — Context & Validation

PR #38159 Pre-Flight

Pull request

  • Title: [Android]Fix Navigation stops working when changing Window[0].Page from Shell
  • State: Open draft against main
  • Issue: #38026, [Android] Navigation stops working when changing Window[0].Page from Shell
  • Local review commit: e328e22ea8cae321283928030dd87440f15b5e22
  • Merge base: 7a2ed62f6de5b9556778c40beda39a7e11d1403f
  • Platform: Android, specifically the Android 16 / API 36 system-back path

The reported sequence is NavigationPage -> Shell -> NavigationPage. After the
Shell has been replaced as Window.Page, hardware back and navigation-bar back
can stop working until the app is force-closed. The PR's root-cause hypothesis
is that the outgoing compatibility Shell's DrawerLayout leaves an Android
system-back callback registered, and that stale callback shadows the incoming
NavigationPage.

Existing PR approach

The production diff changes three existing files:

  1. src/Controls/src/Core/Window/Window.cs
    • During OnPageChanging, recursively searches the outgoing page/container
      tree for either a compatibility ShellRenderer or FlyoutViewHandler.
    • Calls a renderer-specific callback-release method before
      SendDisappearing.
  2. src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellRenderer.cs
    • On API 36+, forwards callback release to its ShellFlyoutRenderer.
  3. src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs
    • Suppresses drawer state/closed callbacks during release.
    • Closes an attached open drawer and sets LockModeLockedClosed, relying on
      AndroidX DrawerLayout to unregister its system-back callback.

This is a proactive, page-tree traversal approach initiated globally by
Window.OnPageChanging. Alternative candidates must use a genuinely different
mechanism/root-cause intervention, not merely move the same traversal or lock
call to another nearby method.

The PR also adds:

  • src/Controls/tests/TestCases.HostApp/Issues/Issue38026.cs
  • src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38026.cs

The UI scenario installs a NavigationPage, switches to a flyout Shell, opens
the flyout, replaces the Shell with another NavigationPage, presses Android
back, and asserts that ReplacementPageLabel disappears.

Gate evidence

The prior gate is definitively failed and must not be rerun:

  • Issue38026 passed without the PR production fix on the initial run and two
    confirmation runs.
  • Issue38026 also passed with the PR fix.
  • Therefore the test is currently non-discriminating; a pass cannot establish
    that a candidate fixes #38026.
  • The gate artifacts remain under
    CustomAgentLogsTmp/PRState/38159/PRAgent/gate/; do not overwrite
    gate/content.md.

Bounded test command

Use only the detected primary UI test:

pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform android -TestFilter "Issue38026"

No separately named mandatory regression tests were supplied in the STEP 5a
request. Do not substitute the detected SafeAreaEdges or Window categories
for a named test, and do not run a full/category-wide suite. Each candidate gets
one implementation/test pass and at most one focused correction/retest.

Try-fix boundaries

  • Each invocation must run the try-fix skill exactly once.
  • Establish and restore the baseline only with
    .github/scripts/EstablishBrokenBaseline.ps1.
  • After baseline establishment, the modification allow-list is expected to be
    the three production files above. Obey the actual
    .github/.baseline-state.json; do not edit the two PR-added test files.
  • The repository contains numerous pre-existing harness changes under
    .github/ and eng/. They are outside this task and must remain untouched.
  • Perform the skill's inline expert self-review; do not launch another agent.
  • A blocked or failed empirical result is valid and must be recorded honestly,
    especially because the primary test does not reproduce the defect.

Pre-flight assessment

The PR targets a plausible AndroidX DrawerLayout callback-lifecycle defect,
but the current automated test provides no causal evidence for either the PR
fix or an alternative. STEP 5a should therefore produce at most two narrowly
implemented, restored candidates with complete artifacts and explicit
mechanism-level comparison. Final code-quality judgment belongs to STEP 5b.


🔬 Code Review — Deep Analysis

Expert PR Evaluation

Verdict: NEEDS_DISCUSSION
Confidence: low

The submitted Android fix extends outgoing-page cleanup to the compatibility ShellRenderer / ShellFlyoutRenderer path, mirroring the existing FlyoutViewHandler cleanup. On Android API 36 and later, it closes an open flyout and locks the outgoing drawer closed during Window.Page replacement so the stale platform back callback is released.

The single MAUI expert-review pass found no actionable defects on added or modified lines, and inline-findings.json therefore contains an empty JSON array. The _releasingDrawerCallback guard prevents the forced close from propagating a spurious FlyoutIsPresented update, and the behavior is scoped to the Android page-replacement lifecycle.

The approach is internally consistent with the submitted regression coverage for replacing a Shell with a NavigationPage and then navigating back. However, the trusted Gate failed, so this code assessment is not merge approval and the candidate comparison must account for the failed regression evidence.


🛠️ Try-Fix — Analysis & Comparison

PR #38159 Alternative Fix Candidates

Candidate 1 — Lifecycle-driven renderer teardown

Model: gpt-5.3-codex

Approach: Release the outgoing compatibility Shell callback as part of
ShellRenderer disconnect/detach cleanup, so Android view lifecycle teardown
removes the DrawerLayout callback rather than relying on a proactive global
page-tree search.

Prior approach avoided: The PR traverses the outgoing page tree from
Window.OnPageChanging, forwards through ShellRenderer, and closes/locks the
flyout while suppressing drawer callbacks. Candidate 1 instead targeted
disconnect/detach causality and intentionally avoided the traversal and
close/LockModeLockedClosed sequence.

Result: Blocked

The mandatory baseline command refused to establish a baseline because the
shared worktree already contains numerous harness-owned changes under
.github/ and eng/. .github/.baseline-state.json was not created, so no
RevertedFiles modification allow-list existed. The candidate correctly made
no tracked-file changes and ran the exact restore command, which reported that
no baseline state existed.

Files changed: None.

Test: Not run. The only permitted command would have been:

pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform android -TestFilter "Issue38026"

The prior gate remains non-discriminating because Issue38026 passed both
without and with the PR fix. Self-review recorded zero findings because there
was no implementation diff.

Captured diff: Empty.

Artifacts:

  • Candidate report:
    CustomAgentLogsTmp/PRState/38159/PRAgent/try-fix-1/content.md
  • Attempt:
    CustomAgentLogsTmp/PRState/38159/PRAgent/try-fix/attempt-1

Candidate 2 — Refresh incoming navigation back registration

Model: gpt-5.6-sol

Approach: After Window.OnPageChanged has fully installed the replacement
root page, refresh the existing Android activity-level predictive-back
registration so its enabled state is derived from the incoming
NavigationPage stack.

Prior approaches avoided: The PR removes the outgoing callback through
global page-tree traversal plus Shell drawer close/lock suppression. Candidate
1 instead proposed removal during ShellRenderer disconnect/detach. Candidate
2 targets incoming callback ownership/state after root installation: it would
re-evaluate the MAUI back bridge from the new navigation stack without
traversing the outgoing tree, manipulating the drawer, or depending on outgoing
renderer teardown.

Result: Blocked

The mandatory baseline command again rejected the pre-existing dirty
harness-owned worktree. .github/.baseline-state.json remained absent, so no
tracked-file modification was permitted. Candidate 2 made no changes, did not
alter candidate 1, and ran the exact restore command; the expected no-state
result was No baseline state found / Restored False.

Files changed: None. The planned target was
src/Controls/src/Core/Window/Window.cs.

Test: Not run. The only permitted command would have been:

pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform android -TestFilter "Issue38026"

This environmental block provides no evidence for or against the candidate.
The test would in any case remain non-discriminating based on the prior gate.
Self-review recorded zero findings because there was no implementation diff.

Captured diff: Empty.

Artifacts:

  • Candidate report:
    CustomAgentLogsTmp/PRState/38159/PRAgent/try-fix-2/content.md
  • Attempt:
    CustomAgentLogsTmp/PRState/38159/PRAgent/try-fix/attempt-2

Aggregate outcome

Two candidates were generated, satisfying the requested bound, but neither
could be implemented or tested safely. Both attempts were independently
blocked at baseline establishment by pre-existing harness changes, and both
left the three PR production files without attempt-created working-tree drift.
No candidate should be treated as validated. The failed gate also means the
existing Issue38026 UI test cannot distinguish a real fix from the broken
baseline.


📝 PR Finalize — Recommended Title & Description

Assessment: ✏️ Recommend updating — the current title is malformed and omits the Shell component, while the description claims an incoming back-navigation refresh that the submitted diff does not add.

Recommended title

[Android] Shell: Restore back navigation after replacing Window.Page

Recommended description

### Issue Details

On Android 16 (API 36), replacing `Window.Page` from a `Shell` to a `NavigationPage` can leave the outgoing compatibility Shell's AndroidX `DrawerLayout` back callback registered. This stale callback intercepts Android back navigation even though the Shell is no longer visible.

### Description of Change

Before the outgoing page disappears, the fix:

* Extends `Window.OnPageChanging`'s existing flyout cleanup to detect an outgoing compatibility `ShellRenderer` in the page-container tree.
* On Android API 36 and later, forwards cleanup from `ShellRenderer` to its `ShellFlyoutRenderer`.
* Closes the attached flyout when necessary and sets the `DrawerLayout` to `LockModeLockedClosed`, while suppressing the resulting drawer callbacks so cleanup does not change `Shell.FlyoutIsPresented`.

This releases the stale `DrawerLayout` back callback before the old Shell is torn down and restores back navigation after switching to a `NavigationPage`.

The Android `Issue38026` UI scenario covers `NavigationPage` → `Shell`, opening the Shell flyout, replacing the Shell with another `NavigationPage`, and pressing Back.

### Issues Fixed

Fixes #38026

**Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189" width="300" height="600"> | **Android**<br> <video src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc" width="300" height="600"> |

🏁 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Winner: pr

The raw submitted PR is the single winning candidate. It is the only implemented fix, it directly releases the outgoing compatibility Shell's AndroidX DrawerLayout back callback, and the one permitted MAUI expert-review pass found no actionable code defects. This recommendation is nevertheless REQUEST CHANGES because the trusted Gate failed: Issue38026 passes repeatedly without the production fix as well as with it, so the submitted regression test does not demonstrate the defect or protect the fix.

Candidate comparison

Rank Candidate Implementation Expert assessment Validation evidence Comparative result
1 pr Complete submitted fix No actionable findings; inline-findings.json is [] The focused UI test passes with the fix, but also passes on the broken baseline; trusted Gate failed Winner. Strongest concrete, root-cause-oriented implementation, but not approval-ready without a discriminating regression test
2 pr-plus-reviewer Production fix equivalent to pr; no actionable reviewer delta existed above the trusted infrastructure-overlay baseline Same assessment as pr Not rerun because there was no refinement and the Gate must not be rerun; inherits the same failed Gate evidence Sound but adds neither product code nor evidence, so it cannot outrank the submitted PR
3 try-fix-1 Planned lifecycle-driven ShellRenderer detach cleanup; no diff produced No implementation available to review Blocked before testing because baseline establishment rejected the dirty shared worktree Plausibly targets stale callback teardown, but remains an unimplemented hypothesis
4 try-fix-2 Planned refresh of incoming navigation back registration; no diff produced No implementation available to review Blocked before testing for the same baseline-state reason Least supported: it does not directly remove the outgoing DrawerLayout callback identified by the available root-cause evidence

No candidate failed the focused UI test: the two implemented-equivalent candidates inherit a passing but non-discriminating result, while both try-fix-* candidates were blocked before execution. Consequently, there is no passed-vs-failed regression-test result that can establish correctness; blocked candidates rank below the implemented PR, and the failed Gate remains decisive.

Required change before approval

Replace or strengthen the Android API 36 regression coverage so it reliably fails against the broken baseline and passes with the submitted production fix. The expert review supplies no production-code correction to apply, and the two STEP 5a alternatives provide no tested implementation that should replace the PR.


📱 UI Tests — SafeAreaEdges,Window

Detected UI test categories: SafeAreaEdges,Window

⚠️ Deep UI tests — 92 passed, 0 failed across 2 categories on platform-pool agent (replaces in-process counts above). 10 new snapshot tests need a baseline PNG (added separately by a maintainer — not a regression). 1 category reported 0 tests.

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
SafeAreaEdges 92/102 (10 ⚠ new baseline) —
Window 0 tests —
🔍 AI analysis of failures — PR-related vs unrelated

🔍 AI-generated triage (GitHub Copilot CLI) — a heuristic judgement of whether each deep UI test failure is connected to this PR's changes. Verify before relying on it.

Likely unrelated: the failures appear pre-existing, flaky, or infrastructure.

  • ● Unrelated — Missing Android screenshot baselines (10 tests): every failure stops at Baseline snapshot not yet created, and the PR changes neither these visual tests nor their Android baseline files, so no rendering comparison occurred from which to attribute a product regression.

Strongest signal: even the Shell flyout cases reached screenshot verification and failed solely because no baseline existed, not because an image differed.

⚠️ SafeAreaEdges — 10 new snapshot tests need a baseline PNG

These tests call VerifyScreenshot but their baseline image isn't committed yet (brand-new snapshot tests get their baseline added separately by a maintainer). There's nothing to compare against, so this is not a regression — download the drop-deep-uitests artifact, confirm the rendering, and commit the baseline PNG.

  • ToolbarExtendsAllTheWayLeftAndRight_NavigationPage
  • VerifyDefaultFlyoutItemsRendering
  • VerifyFlyoutWithHeaderFooter
  • VerifyCustomFlyoutContentWithHeaderFooter
  • LayoutShouldBeCorrectOnFirstNavigation
  • ToolbarExtendsAllTheWayLeftAndRight_FlyoutPage
  • VerifyCustomFlyoutContentRendering
  • VerifyCustomFlyoutContentTemplateWithHeaderFooter
  • VerifyCustomFlyoutContentTemplateRendering
  • ToolbarExtendsAllTheWayLeftAndRight_Shell

📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)


🧭 Next Steps — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-failed AI could not verify tests catch the bug s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) and removed s/agent-review-in-progress AI review is currently running for this PR labels Sep 3, 2026
@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

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.

🟡 Changes recommended

The added UI test metadata/commenting is inconsistent with the test’s actual intent (category/remarks), and the PR description appears to overstate the implemented behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes an Android 16 (API 36+) regression where back navigation can stop working after replacing Window.Page from a Shell to a NavigationPage, by proactively releasing the outgoing Shell/Flyout drawer’s system-back callback before the old page tree is torn down.

Changes:

  • Add an Android-only teardown step in Window.OnPageChanging to release DrawerLayout back callbacks from outgoing pages.
  • Introduce a compatibility ShellRenderer → ShellFlyoutRenderer path to close/lock the DrawerLayout during page replacement on API 36+.
  • Add a HostApp repro page and an Android UI test for issue #38026.
File summaries
File Description
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38026.cs Adds an Android-only UI test validating back navigation after swapping Window.Page from Shell to NavigationPage.
src/Controls/tests/TestCases.HostApp/Issues/Issue38026.cs Adds a HostApp repro page that switches between NavigationPage and Shell and opens the flyout before replacement.
src/Controls/src/Core/Window/Window.cs Releases outgoing DrawerLayout back callbacks on Android before SendDisappearing() during page replacement.
src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellRenderer.cs Adds an API 36+ helper to release the Shell DrawerLayout callback before the page change.
src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs Adds a release routine to close/lock the DrawerLayout and guards flyout state propagation during that internal operation.
Review details

Suppressed comments (1)

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38026.cs:18

  • This test is categorized as SafeAreaEdges, but it’s validating back/navigation behavior when swapping Window.Page from Shell. Using a more relevant category helps ensure it runs in the intended CI slices and keeps category meaning consistent.
	[Test]
	[Category(UITestCategories.SafeAreaEdges)]
	public void BackWorksAfterReplacingShellWithNavigationPage()
  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Lite

Comment on lines 673 to 684
// the FlyoutPage) and the nested case (e.g. NavigationPage wrapping a FlyoutPage).
static void ReleaseFlyoutDrawerCallbacks(Page page)
{
if (page.Handler is Handlers.Compatibility.ShellRenderer compatibilityShellRenderer)
{
compatibilityShellRenderer.ReleaseDrawerCallbackBeforePageChange();
return;
}

if (page.Handler is FlyoutViewHandler flyoutHandler)
{
flyoutHandler.ReleaseDrawerCallbackBeforePageChange();
Comment on lines +34 to +38
sealed class TestShell : Shell
{
public TestShell()
{
FlyoutBehavior = FlyoutBehavior.Flyout;
@@ -0,0 +1,39 @@
#if ANDROID // This issue is reproduced only on Android API 36, so added an Android-specific test and restricted it from running on other platforms, also categorized the test under SafeAreaEdges.
@kubaflo
kubaflo changed the base branch from main to inflight/current September 4, 2026 16:26
@kubaflo
kubaflo merged commit 6c9163e into dotnet:inflight/current Sep 4, 2026
149 of 169 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR11 milestone Sep 4, 2026
kubaflo pushed a commit that referenced this pull request Sep 6, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Sep 7, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Sep 8, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Sep 9, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Sep 11, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Sep 15, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Sep 18, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Sep 21, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Sep 27, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Sep 27, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Oct 3, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
kubaflo pushed a commit that referenced this pull request Oct 3, 2026
…om Shell (#38159)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details
On Android 16, replacing Window.Page from Shell to NavigationPage leaves
Shell’s old DrawerLayout back callback registered. This stale callback
intercepts Android back navigation even though Shell is no longer
visible.

### Description of Change

<!-- Enter description of the fix in this section -->
Before replacing Window.Page, the fix: 
* Detects an outgoing Shell. Closes its flyout if open. 
* Locks the DrawerLayout closed to release its back callback. 
* Refreshes Android’s back-navigation state after installing the new
page.

This restores back navigation after switching from Shell to
NavigationPage.

### 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 #38026 

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

 **Tested the behavior in the following platforms.**
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

| Before  | After  |
|---------|--------|
| **Android**<br> <video
src="https://github.com/user-attachments/assets/cc202510-daff-4788-80b0-fae2d8cec189"
width="300" height="600"> | **Android**<br> <video
src="https://github.com/user-attachments/assets/f2cb6881-e5be-4746-8680-15bc5ff68afc"
width="300" height="600"> |
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 5, 2026
@github-actions github-actions Bot modified the milestones: .NET 10 SR11, .NET 10 SR12 Oct 21, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 1ee5535c Deployed Sep 3, 2026 by devanathan-vaithiyanathan via conclusion #1727
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-shell Shell Navigation, Routes, Tabs, Flyout community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-gate-failed AI could not verify tests catch the bug s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Navigation stops working when changing Window[0].Page from Shell

5 participants