[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
Open
Conversation
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. |
Contributor
|
/azp run maui-pr-uitests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Issues Fixed
Fixes #34636
Output ScreenShot