-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix for CarouselView reverts to displaying 1st item in collection when collection modified #26608
base: main
Are you sure you want to change the base?
Conversation
Hi @jsuarezruiz, We have fixed the issue. On Windows, ItemsUpdatingScrollMode is considered during collection updates. For Android and iOS, we have implemented code changes to ensure consistent behavior across all platforms and test cases for this issue are already included in the 26160 PR |
if (_positionAfterUpdate == -1) | ||
{ | ||
return; | ||
} | ||
|
||
_gotoPosition = -1; | ||
|
||
var targetPosition = _positionAfterUpdate; | ||
// We need to update the position while modifying the collection. |
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.
I think we might want for clear read refactor this on this one method ?
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.
I think we might want for clear read refactor this on this one method ?
Hi @rmarinho , Not clear about your concern.Are you suggesting improvements to the method's implementation itself, or are you referring to enhancing the comments we've added to this method?
// We need to update the position while modifying the collection. | ||
if (ItemsView.ItemsUpdatingScrollMode == ItemsUpdatingScrollMode.KeepItemsInView) | ||
{ | ||
targetPosition = 0; |
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.
won t this always scroll to the first position ?
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.
won t this always scroll to the first position ?
Yes, based on the documentation and behavior of the Windows platform, we implemented code changes to update the scrollposition
according to the ItemsUpdatingScrollMode
. When ItemsUpdatingScrollMode
is set to KeepItemsInView
, the scroll position will adjust to the first item in view. To maintain the scrolled index, KeepScrollOffset
should be used instead.
Issue Details
Behavior in windows: When modifying the collection, the CarouselView scrolls to display the first item. This is the expected behavior when considering the ItemsUpdatingScrollMode.
Android and iOS: While updating the collection, ItemsUpdatingScrollMode is not respected, causing the current position to deviate from the expected behavior for keeping items in view.
Root Cause
Android: In the MauiCarouselRecyclerView, the ItemsUpdatingScrollMode is not applied during the ItemsCollectionChanged event. As a result, the CarouselView maintains the position of the previously scrolled item.
iOS and Mac: In the CarouselViewController, the collection update ignores the ItemsUpdatingScrollMode, and the current position remains unchanged, irrespective of the scroll mode settings.
Fix Details
Android: Updated the MauiCarouselRecyclerView to adjust the carousel position based on the ItemsUpdatingScrollMode during collection updates.
iOS and Mac: Incorporated the ItemsUpdatingScrollMode into the collection update logic to ensure the position is updated appropriately according to the specified scroll mode.
Issues Fixed
Fixes #25991
Output Screenshot
Screen.Recording.2024-12-12.at.8.33.19.PM.mov
Screen.Recording.2024-12-12.at.8.30.44.PM.mov