Skip to content

[release/10.0.1xx-sr7] [iOS, Mac] Fix OnBackButtonPressed not invoked for NavigationPage and Shell#35434

Merged
PureWeen merged 3 commits into
release/10.0.1xx-sr7from
backport/pr-35072-to-release/10.0.1xx-sr7
May 15, 2026
Merged

[release/10.0.1xx-sr7] [iOS, Mac] Fix OnBackButtonPressed not invoked for NavigationPage and Shell#35434
PureWeen merged 3 commits into
release/10.0.1xx-sr7from
backport/pr-35072-to-release/10.0.1xx-sr7

Conversation

@kubaflo
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo commented May 13, 2026

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!

Manual backport of #35072 to release/10.0.1xx-sr7.

Why this is a manual backport

The automated /backport workflow (failed run) hit a modify/delete conflict on src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue9095.cs. The file is added by #35150 (already backported as #35430, currently OPEN) and modified by #35072. Because #35430 is not yet merged into release/10.0.1xx-sr7, the file does not exist on the target branch and the patch could not apply cleanly.

Resolution

Cherry-picked the squashed merge commit 7023635baac2524ab02f602e56fd7608142984a1 of #35072 onto release/10.0.1xx-sr7. Resolved the conflict by keeping the post-merge version of Issue9095.cs (verified byte-identical to inflight/current, which contains both #35150's added content and #35072's tweaks).

⚠️ Dependency on #35430

This PR's diff currently shows Issue9095.cs as a new file because it includes content originally introduced by #35150. Recommended merge order:

  1. Merge [release/10.0.1xx-sr7] [Android] Fix OnBackButtonPressed not invoked for Shell #35430 (Android backport of [Android] Fix OnBackButtonPressed not invoked for Shell #35150) first.
  2. This PR will then auto-rebase to show only [iOS, Mac] Fix OnBackButtonPressed not invoked for NavigationPage and Shell #35072's incremental delta (a 2-line change to Issue9095.cs and the ShellSectionRenderer.cs / NavigationRenderer.cs / Issue8296.cs changes).

Alternatively, this PR can be merged first, but #35430 will then need a manual conflict resolution (the file would already exist).

Fixes #8296 in release/10.0.1xx-sr7.

… Shell (#35072)

<!-- 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!

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

when the native navigation bar back button is tapped inside a
NavigationPage.

button is tapped on Android and iOS Shell pages

- ShouldPopItem in NavigationRenderer.cs (the
navigationBar:shouldPopItem: UIKit delegate callback) fires when the
user taps the native iOS back button.
- Previously it unconditionally set _uiRequestedPop = true and returned
true, allowing the native pop without ever notifying MAUI's page model.
As a result, ContentPage.OnBackButtonPressed was never called on iOS
when the native back button was tapped inside a NavigationPage.

- Same issue — tracker.Value.Page?.SendBackButtonPressed() skipped the
Shell chain and went directly to the ContentPage.

- In ShouldPopItem, call NavPage?.CurrentPage?.SendBackButtonPressed()
before allowing the native pop. If it returns true (the page
handled/cancelled back navigation), reset _uiRequestedPop and return
false to prevent the native pop.

- Route through _context.Shell?.SendBackButtonPressed() instead of
tracker.Value.Page?.SendBackButtonPressed(), so the Shell back button
tap goes through the same chain as the system back button.

**Note** on _sendPopPending = false in the BackButtonBehavior command
path: On iOS 26+, _sendPopPending is set to true unconditionally at the
start of SendPop(), before any BackButtonBehavior checks. When a
BackButtonBehavior.Command executes and returns false (preventing
navigation), ViewDidDisappear never fires — so without an explicit
reset, the flag stays true permanently and silently blocks all
subsequent back presses. The _sendPopPending = false after command
execution (line 188) is therefore an intentional and necessary fix to
prevent the back button becoming permanently unresponsive after a
command-handled back press on iOS 26+.

| Platform | Navigation | `OnBackButtonPressed` |
|---|---|---|
| iOS / MacCatalyst | `GoToAsync` | ✅ Triggered |
| Android | `GoToAsync` | ✅ Triggered (app back button and emulator back
button) |
| Windows | `GoToAsync` | ✅ Triggered |

>`OnBackButtonPressed` is triggered for both the `Shell` and the
contained `ContentPage`.

| Platform | Navigation | `OnBackButtonPressed` | Notes |
|---|---|---|---|
| iOS / MacCatalyst | `PushAsync` | ✅ Triggered | |
| iOS / MacCatalyst | `PushModalAsync` | — | Back button not visible in
modal navigation |
| Android | `PushAsync` | ✅ Triggered (app back button and emulator back
button) | |
| Android | `PushModalAsync` | ✅ Triggered | Called on the modal
ContentPage |
| Windows | `PushAsync` | ✅ Triggered | |
| Windows | `PushModalAsync` | — | Back button not visible in modal
navigation |

> On Android and Windows, `OnBackButtonPressed` is triggered for both
the `NavigationPage` and the contained `ContentPage`.

| Platform | Navigation | `OnBackButtonPressed` | Notes |
|---|---|---|---|
| iOS / MacCatalyst | `PushAsync` | ✅ Triggered | |
| iOS / MacCatalyst | `PushModalAsync` | — | Back button not visible in
modal navigation |
| Android | `PushAsync` | ✅ Triggered | |
| Android | `PushModalAsync` | ✅ Triggered | |
| Windows | `PushAsync` | ✅ Triggered | |
| Windows | `PushModalAsync` | — | Back button not visible in modal
navigation |

| Platform | Navigation | `OnBackButtonPressed` | Notes |
|---|---|---|---|
| iOS / MacCatalyst | `PushAsync` | ✅ Triggered | |
| iOS / MacCatalyst | `PushModalAsync` | — | Back button not visible in
modal navigation |
| Android | `PushAsync` | ✅ Triggered | |
| Android | `PushModalAsync` | ✅ Triggered | |
| Windows | `PushAsync` | ✅ Triggered | |
| Windows | `PushModalAsync` | — | Back button not visible in modal
navigation |

- [ ] Android
- [ ] Windows
- [x] iOS
- [x] Mac

Fixes #8296

|  | Before  | After |
|--|---------|--------|
|8296|  <video
src="https://github.com/user-attachments/assets/13887369-e9e9-42df-a2a0-db88f0e6b38f">
|   <video
src="https://github.com/user-attachments/assets/d0ccfb01-59e8-44bc-8878-54c5d0f6fb7e"> 
|
|9095 |  <video
src="https://github.com/user-attachments/assets/664e0b7f-3964-4a1b-a4f6-46b1db758b48">
|   <video
src="https://github.com/user-attachments/assets/3ff159ec-93b0-4a91-854a-ca23211ff204"> 
|

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 7023635)
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

🚀 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 -- 35434

Or

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

@PureWeen
Copy link
Copy Markdown
Member

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

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@sheiksyedm
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).

@sheiksyedm
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).

@PureWeen PureWeen merged commit c9466bd into release/10.0.1xx-sr7 May 15, 2026
147 of 167 checks passed
@PureWeen PureWeen deleted the backport/pr-35072-to-release/10.0.1xx-sr7 branch May 15, 2026 16:56
@github-actions github-actions Bot added this to the .NET 10 SR7 milestone May 15, 2026
kubaflo pushed a commit that referenced this pull request May 19, 2026
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

 <!-- 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!


Cherry-picks test fixes and snapshot additions from multiple backport
PRs:

- **PR #35434** — Fixed CI failure (removed flaky test attributes from
Bugzilla40333) and removed Issue9095 test
- **PR #35426** — Added mac and Windows snapshots for
`VerifySearchBarHeightRequestValues`, updated iOS snapshots
- **PR #35427** — Resolved device test failures in
`ScrollViewHandler.Windows.cs`
- **PR #35424** — Added mac and Windows snapshots for
`LinearGradientBrushTransparentStopsShouldNotBeOpaque`
- **PR #35425** — Removed failing test: "Missing ControlTemplate with
exception handler should throw" (`StaticResourceTests.cs`)

## Changes

| File | Change |
|------|--------|
| `Bugzilla40333.cs` | Removed 2 lines (CI fix) |
| `Issue9095.cs` | Deleted |
| `ScrollViewHandler.Windows.cs` | Fixed device test failures |
| `StaticResourceTests.cs` | Deleted |
| SearchBar snapshots (mac/windows/iOS) | Added/updated |
| LinearGradientBrush snapshots (mac/windows) | Added |

---------

Co-authored-by: Dhivya-SF4094 <127717131+Dhivya-SF4094@users.noreply.github.com>
Co-authored-by: devanathan-vaithiyanathan <114395405+devanathan-vaithiyanathan@users.noreply.github.com>
Co-authored-by: Vignesh-SF3580 <102575140+Vignesh-SF3580@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Jun 2, 2026
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

 <!-- 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!


Cherry-picks test fixes and snapshot additions from multiple backport
PRs:

- **PR #35434** — Fixed CI failure (removed flaky test attributes from
Bugzilla40333) and removed Issue9095 test
- **PR #35426** — Added mac and Windows snapshots for
`VerifySearchBarHeightRequestValues`, updated iOS snapshots
- **PR #35427** — Resolved device test failures in
`ScrollViewHandler.Windows.cs`
- **PR #35424** — Added mac and Windows snapshots for
`LinearGradientBrushTransparentStopsShouldNotBeOpaque`
- **PR #35425** — Removed failing test: "Missing ControlTemplate with
exception handler should throw" (`StaticResourceTests.cs`)

## Changes

| File | Change |
|------|--------|
| `Bugzilla40333.cs` | Removed 2 lines (CI fix) |
| `Issue9095.cs` | Deleted |
| `ScrollViewHandler.Windows.cs` | Fixed device test failures |
| `StaticResourceTests.cs` | Deleted |
| SearchBar snapshots (mac/windows/iOS) | Added/updated |
| LinearGradientBrush snapshots (mac/windows) | Added |

---------

Co-authored-by: Dhivya-SF4094 <127717131+Dhivya-SF4094@users.noreply.github.com>
Co-authored-by: devanathan-vaithiyanathan <114395405+devanathan-vaithiyanathan@users.noreply.github.com>
Co-authored-by: Vignesh-SF3580 <102575140+Vignesh-SF3580@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants