-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS][CV2]Fixed Selected item color changes from lightskyblue to lightgray after scrolling when deploying ManualMaui Demo project on iOS 26.1 #32822
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
Conversation
…r scrolling when deploying ManualMaui Demo project on iOS 26.1
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
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.
Pull request overview
This PR fixes an iOS-specific issue where CollectionView selected item background colors defined via VisualStateManager incorrectly revert to the default gray color when cells are reused during scrolling. The fix ensures that when a cell is reused for a selected item, the correct visual state and selection color are reapplied.
Key Changes:
- Added logic to reapply VisualStateManager states and selection colors when binding a cell that is in the selected state
- The fix is specific to iOS CollectionView2 implementation (Items2 handlers)
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.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Co-authored-by: Copilot <[email protected]>
…r scrolling when deploying ManualMaui Demo project on iOS 26.1 (#32822) Fix optimized Update src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs Co-authored-by: Copilot <[email protected]>
…r scrolling when deploying ManualMaui Demo project on iOS 26.1 (#32822) Fix optimized Update src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs Co-authored-by: Copilot <[email protected]>
Issue Details:
The user has implemented a VisualStateManager for the Grid.BackgroundColor (which is Item template in collectionview) property to apply a selected background color. However, on the iOS platform, the selected item’s background color changes unexpectedly—from LightSkyBlue back to the default gray—when scrolling from bottom to top.
Root Cause:
iOS uses a native UICollectionView, which reuses cells by default. When the collection view loads scrollable items, it initially creates only the cells required for the visible area. As the user scrolls, previously created cells are reused or recreated for new items.
When scrolling back to a previously selected item, the corresponding cell is reused and recreated. At this point, the selected cell incorrectly receives the default gray background color, because in the GetCell method of the ItemsViewController2 class (line 112). the reused cell is instantiated with the default background color defined in the constructor of ItemsViewCell2. The selected background color is not re-applied to the reused cell, causing the color to appear as gray.
Description of Change:
To ensure the correct selected state is applied when a cell is reused:
These updates were added to the BindVirtualView method in the TemplatedCell2 class to ensure the correct selected background color is consistently applied, even when cells are reused.
Tested the behavior in the following platforms.
The test case for this scenario is not included in this PR, because the issue occurs very randomly. So, manually tested the fix.
Reference:
N/A
Issues Fixed:
Fixes #32493
Closes #32795
Screenshots
BeforeFix.mov
AfterFix.mov