-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fixed [Windows] KeepLastItemInView Behavior Not Working as Expected in CarouselView #29550
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
Hey there @@NanthiniMahalingam! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 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 the KeepLastItemInView behavior in CarouselView on Windows by adjusting how the last item is identified and preventing unwanted scroll operations when the carousel is resized.
- Updated the item count calculation in OnItemsVectorChanged to avoid using fake looping items.
- Restricted the ScrollTo call in UpdateCurrentItem when the current item is already in view.
- Added test cases in both shared tests and the host app to validate the behavior on Windows (and other platforms).
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29420.cs | Added test case for KeepLastItemInView on platforms failing the behavior |
src/Controls/tests/TestCases.HostApp/Issues/Issue29420.cs | Host test implementation verifying the fixed behavior |
src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs | Modified item count logic to differentiate between fake looping items and actual items |
src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Windows.cs | Added a safeguard in UpdateCurrentItem to avoid unnecessary scroll operations |
@@ -133,7 +133,8 @@ void OnItemsVectorChanged(global::Windows.Foundation.Collections.IObservableVect | |||
if (sender is not ItemCollection items) | |||
return; | |||
|
|||
var itemsCount = items.Count; | |||
// When looping is enabled in CarouselView, Items.Count returns the FakeCount instead of the actual item count. |
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.
[nitpick] Consider adding an inline comment clarifying why VirtualView is being checked against CollectionView and what types are expected; this will help future maintainers understand the intended behavior when selecting between items.Count and ItemCount.
// When looping is enabled in CarouselView, Items.Count returns the FakeCount instead of the actual item count. | |
// When looping is enabled in CarouselView, Items.Count returns the FakeCount instead of the actual item count. | |
// Use items.Count for CollectionView to account for this behavior; otherwise, use ItemCount for other types. |
Copilot uses AI. Check for mistakes.
@@ -381,8 +381,10 @@ void UpdateCurrentItem() | |||
|
|||
var currentItemPosition = GetItemPositionInCarousel(ItemsView.CurrentItem); | |||
|
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.
[nitpick] It would be helpful to add a brief comment explaining the rationale for including the check against ItemsView.Position, so that the intention to prevent unnecessary scrolling when the current item is already visible is clearly documented.
// If the current item is already visible (ItemsView.Position == currentItemPosition), | |
// avoid unnecessary scrolling to improve performance and user experience. |
Copilot uses AI. Check for mistakes.
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!
Root Cause
Description of Change
Validated the behaviour in the following platforms
Issues Fixed
Fixes #29420
Output
Windows
Issue29420_Before.mp4
Issue29420_After.mp4