[Windows] Fixed KeepLastItemInView Behavior Not Working as Expected in CarouselView#29550
[Windows] Fixed KeepLastItemInView Behavior Not Working as Expected in CarouselView#29550NanthiniMahalingam wants to merge 14 commits intodotnet:inflight/currentfrom
Conversation
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
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 |
| 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.
[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. |
| @@ -381,8 +381,10 @@ void UpdateCurrentItem() | |||
|
|
|||
| var currentItemPosition = GetItemPositionInCarousel(ItemsView.CurrentItem); | |||
|
|
|||
There was a problem hiding this comment.
[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. |
|
/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). |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29420.cs
Outdated
Show resolved
Hide resolved
|
/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). |
| var currentItemPosition = GetItemPositionInCarousel(ItemsView.CurrentItem); | ||
|
|
||
| if (currentItemPosition < 0 || currentItemPosition >= ItemCount) | ||
| if (currentItemPosition < 0 || currentItemPosition >= ItemCount || ItemsView.Position == currentItemPosition) |
There was a problem hiding this comment.
Not an extra long condition, but can increase the readability here adding a couple of variables:
bool isOutOfBounds = currentItemPosition < 0 || currentItemPosition >= ItemCount;
bool isSamePosition = ItemsView.Position == currentItemPosition;
if (isOutOfBounds || isSamePosition)
return;
There was a problem hiding this comment.
Not an extra long condition, but can increase the readability here adding a couple of variables:
bool isOutOfBounds = currentItemPosition < 0 || currentItemPosition >= ItemCount; bool isSamePosition = ItemsView.Position == currentItemPosition; if (isOutOfBounds || isSamePosition) return;
Hi @jsuarezruiz ,
I've refined the fix according to your suggestion to enhance readability.
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
98b5f14 to
71f412c
Compare
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 29550Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 29550" |
71f412c to
991f3a2
Compare
|
/azp run maui-pr-uitests , maui-pr-devicetests |
kubaflo
left a comment
There was a problem hiding this comment.
Could you please resolve conflicts?
1b23515 to
2380dad
Compare
|
@kubaflo I have resolved the conflicts |
🚦 Gate - Test Before and After Fix📊 Expand Full Gate —
|
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
Fixes #29448
Output
Windows
Issue29420_Before.mp4
Issue29420_After.mp4