Skip to content

[Android] Fix CollectionView items not resizing after orientation change on Shell pages - #34420

Merged
kubaflo merged 4 commits into
dotnet:inflight/currentfrom
SyedAbdulAzeemSF4852:fix-19667
Jun 10, 2026
Merged

[Android] Fix CollectionView items not resizing after orientation change on Shell pages#34420
kubaflo merged 4 commits into
dotnet:inflight/currentfrom
SyedAbdulAzeemSF4852:fix-19667

Conversation

@SyedAbdulAzeemSF4852

@SyedAbdulAzeemSF4852 SyedAbdulAzeemSF4852 commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

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

  • When a CollectionView page is opened in portrait mode, then the user navigates to another page, rotates to landscape, and navigates back — the CollectionView items display with portrait dimensions. Only after scrolling do they resize correctly.

Root Cause

  • When navigating away from a CollectionView page in Shell, the page's handler and RecyclerView are reused. If the device rotates while the page is off-screen, Android skips invalidating hidden views, so the children remain marked as "clean". When navigating back, LinearLayoutManager skips remeasuring these "clean" children, causing items to display with portrait dimensions in landscape. As a result, items render at the wrong size until a scroll forces a re-measure.

Description of Change

  • MauiRecyclerView.cs: Added OnSizeChanged() override. Guard: oldw > 0 && oldh > 0 && (Math.Abs(w - oldw) > 1 || Math.Abs(h - oldh) > 1).Calls InvalidateItemMeasures() which: (a) calls adapter.ClearMeasureCache(), (b) iterates visible children calling itemContentView.InvalidateCachedSize() + itemContentView.ForceLayout()
  • ItemsViewAdapter.cs: Added internal virtual void ClearMeasureCache()
  • StructuredItemsViewAdapter.cs: internal override void ClearMeasureCache() sets _size = null
  • ItemContentView.cs: Added internal void InvalidateCachedSize() — resets _pixelSize = null, _previousPixelWidth = -1, _previousPixelHeight = -1
  • PublicAPI.Unshipped.txt: Added OnSizeChanged override entry

Issues Fixed

Fixes #19667
Fixes #31892

Validated the behaviour in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Output

Before After
Before.mov
After.mov

Loading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android 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)

Projects

None yet

10 participants