Skip to content

[release/10.0.1xx-sr7] Gate SafeArea inset listeners in recycler items#35693

Merged
PureWeen merged 3 commits into
release/10.0.1xx-sr7from
backport/pr-35664-to-release/10.0.1xx-sr7
Jun 2, 2026
Merged

[release/10.0.1xx-sr7] Gate SafeArea inset listeners in recycler items#35693
PureWeen merged 3 commits into
release/10.0.1xx-sr7from
backport/pr-35664-to-release/10.0.1xx-sr7

Conversation

@kubaflo
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo commented Jun 1, 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!

Backport of #35664 to release/10.0.1xx-sr7.
/cc @PureWeen

This PR reduces Android `CollectionView`/`CarouselView` item allocation
overhead from SafeArea inset listener attachment.

The Android SafeArea implementation currently attaches inset listeners
to item views under `IMauiRecyclerView`, even when those item views have
default `SafeAreaEdges` behavior. This is expensive during item
realization/recycling and materially increases allocations and GC
pressure in scroll-heavy CollectionView scenarios.

This change gates Android inset listener attachment for descendants of
`IMauiRecyclerView` so listeners are only attached when the target
platform view backs an `ISafeAreaView2` with explicitly configured
`SafeAreaEdges`.

The fix also preserves behavior for dynamic SafeArea changes:

- default item views do not attach inset listeners;
- explicit `SafeAreaEdges` values, including `SafeAreaEdges.None`,
remain eligible;
- changing from default to explicit refreshes and attaches the listener;
- clearing/changing back to default removes the listener and resets
applied padding;
- existing `AppBarLayout`, `MaterialToolbar`, and `MauiScrollView`
exclusions are preserved.

Validation completed:

- `dotnet test
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj
--filter FullyQualifiedName~SafeAreaTests --nologo`
- Android device test build and CollectionView SafeArea listener tests
- MauiAppGC repro, Release Android, explicit APK install, `Reset -> End
-> Start -> End`, 5 repeats:
  - `10.0.70`: ~270 MB allocated, `65/2/2` GCs
  - SafeArea gating patch: ~151 MB allocated, `38/0/0` GCs

Fixes #35344

---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>

(cherry picked from commit 8079709)
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 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 -- 35693

Or

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

@github-actions github-actions Bot added area-safearea Issues/PRs that have to do with the SafeArea functionality platform/android labels Jun 1, 2026
@kubaflo
Copy link
Copy Markdown
Contributor Author

kubaflo commented Jun 1, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@vishnumenon2684
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

Fix GroupableItemsViewAdapter double-bind of GroupHeader/Footer causing unbounded logical children growth on recycle
@vishnumenon2684
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen merged commit 8e91b4a into release/10.0.1xx-sr7 Jun 2, 2026
162 of 168 checks passed
@PureWeen PureWeen deleted the backport/pr-35664-to-release/10.0.1xx-sr7 branch June 2, 2026 21:23
@github-actions github-actions Bot added this to the .NET 10 SR7 milestone Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-safearea Issues/PRs that have to do with the SafeArea functionality platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants