Skip to content

Fix for ItemSpacing value being retained when re-entering CollectionView with ItemsLayout set to vertical or horizontal list after navigating back. #29190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

BagavathiPerumal
Copy link
Contributor

Root cause

The issue was caused because LinearItemsLayout.Vertical and LinearItemsLayout.Horizontal were used as static instances instead of creating new instances in the layout type converter. As these static instances were reused, properties like ItemSpacing retained their previous values when returning to the page using PopAsync. Since the internal items layout property defaulted to the static LinearItemsLayout.Vertical, the layout did not refresh properly, leading to inconsistent or unexpected behavior across all platforms.

Description of Issue Fix

The fix involves replacing the use of static instances (LinearItemsLayout.Vertical and LinearItemsLayout.Horizontal) with newly created instances of LinearItemsLayout to prevent shared state across navigations. This was achieved by updating the layout initialization to use a defaultValueCreator that returns a new LinearItemsLayout instance, and modifying the ItemsLayoutTypeConverter to return new instances based on the orientation string, rather than reusing static ones. This ensures each layout has its own settings, so ItemSpacing doesn't carry over when the page is popped with the back button and opened again using GoToAsync.

Tested the behavior in the following platforms.

  • Windows
  • Mac
  • iOS
  • Android

Issues Fixed

Fixes #28023

Output

Before Issue Fix After Issue Fix
Beforefix-ItemsSpacing.mov
Afterfix-ItemsSpacing.mov

…rItemsLayout instances with new ones in initialization and converter to avoid outdated ItemSpacing on back and GoToAsync navigation.
Copy link
Contributor

Hey there @@BagavathiPerumal! 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 community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Apr 25, 2025
@jsuarezruiz jsuarezruiz added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Apr 25, 2025
App.Tap("PopButton");
App.WaitForElement("NavigatedPageButton");
App.Tap("NavigatedPageButton");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending snapshots on Mac and Windows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snapshots already available in the latest build.

image

Could you commit the images?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz, I have successfully added snapshots for Mac and Windows.

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@BagavathiPerumal BagavathiPerumal marked this pull request as ready for review April 25, 2025 12:36
@BagavathiPerumal BagavathiPerumal requested a review from a team as a code owner April 25, 2025 12:36
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

App.Tap("PopButton");
App.WaitForElement("NavigatedPageButton");
App.Tap("NavigatedPageButton");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snapshots already available in the latest build.

image

Could you commit the images?

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
Projects
None yet
2 participants