Skip to content

[Android] Fix CollectionView LinearItemsLayout first/last items clipped when ItemSpacing changes at runtime#34664

Open
Shalini-Ashokan wants to merge 2 commits intodotnet:inflight/candidatefrom
Shalini-Ashokan:fix_34636
Open

[Android] Fix CollectionView LinearItemsLayout first/last items clipped when ItemSpacing changes at runtime#34664
Shalini-Ashokan wants to merge 2 commits intodotnet:inflight/candidatefrom
Shalini-Ashokan:fix_34636

Conversation

@Shalini-Ashokan
Copy link
Contributor

@Shalini-Ashokan Shalini-Ashokan commented Mar 26, 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!

Issue Details

CollectionView with LinearItemsLayout, the first and last items become truncated/clipped after changing the ItemSpacing value at runtime. This affects both vertical and horizontal list orientations on Android.

Note: This is inflight/candate branch changes where exsiting PR #27093 causes the regression on this branch. So added this new fix to overcome the regression.

Root Cause

PR #27093 changed SpacingItemDecoration.GetItemOffsets to zero out the outer edge offsets (outRect.Top = 0 for item 0, outRect.Bottom = 0 for last item) for all layout types including LinearItemsLayout. However, MauiRecyclerView.UpdateItemSpacing still applied negative padding (SetPadding(-offset, ...)) on the RecyclerView for linear layouts. This conflict caused the first and last items to be pulled outside the visible area and clipped, since the positive offset that was supposed to cancel the negative padding was removed.

Description of Change

Added a _removeOuterEdgeSpacing boolean flag to SpacingItemDecoration, set to true only for GridItemsLayout. In GetItemOffsets, an early return is added when _removeOuterEdgeSpacing is false, skipping the edge-zeroing logic for LinearItemsLayout. This restores the correct balanced behavior for linear lists: the positive outRect offset (+N) and the negative RecyclerView padding (-N) cancel each other out at the edges, keeping the first and last items correctly positioned at the screen boundary.

Validated the behavior in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #34636

Output ScreenShot

Before After
BeforeFix AfterFix

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Mar 26, 2026
@dotnet-policy-service
Copy link
Contributor

Hey there @@Shalini-Ashokan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Mar 26, 2026
@sheiksyedm sheiksyedm added platform/android area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Mar 26, 2026
@sheiksyedm sheiksyedm marked this pull request as ready for review March 26, 2026 08:36
@sheiksyedm sheiksyedm added this to the .NET 10 SR6 milestone Mar 26, 2026
@sheiksyedm
Copy link
Contributor

/azp run maui-pr-uitests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dotnet dotnet deleted a comment from azure-pipelines bot Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants