-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: main
Are you sure you want to change the base?
Conversation
…rItemsLayout instances with new ones in initialization and converter to avoid outdated ItemSpacing on back and GoToAsync navigation.
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. |
App.Tap("PopButton"); | ||
App.WaitForElement("NavigatedPageButton"); | ||
App.Tap("NavigatedPageButton"); | ||
VerifyScreenshot(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
App.Tap("PopButton"); | ||
App.WaitForElement("NavigatedPageButton"); | ||
App.Tap("NavigatedPageButton"); | ||
VerifyScreenshot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Issues Fixed
Fixes #28023
Output
Beforefix-ItemsSpacing.mov
Afterfix-ItemsSpacing.mov