-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix CarouselView PreviousPosition updating when inserting items #29617
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 @@Shalini-Ashokan! 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). |
// Updates position to match current item when inserting items, correctly tracking previous position values. | ||
if (currentItemPosition != carouselPosition && ItemsView.ItemsUpdatingScrollMode == ItemsUpdatingScrollMode.KeepItemsInView) | ||
{ | ||
if (InitialPositionSet && currentItemPosition > -1) |
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.
Can nest this two conditions in a single one, but would be better to create a variable to increase the readability:
var shouldUpdatePosition =
currentItemPosition != carouselPosition &&
ItemsView.ItemsUpdatingScrollMode == ItemsUpdatingScrollMode.KeepItemsInView &&
InitialPositionSet &&
currentItemPosition > -1;
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 updated the code section based on your suggestions.
Margin = new Thickness(20), | ||
}; | ||
|
||
insertButton.Clicked += (sender, e) => |
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.
Could include another button to remove the current item and verify the PositionChanged event parameter?
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 included the test case for the remove action.
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
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!
Issue Details
In the CarouselView control, when items are added at index 0, the PreviousPosition property in the PositionChangedEventArgs does not update correctly.
Root Cause
When items are inserted at index 0, explicitly setting the position to the current item position (currentItemPosition) prevents the actual position from changing. As a result, the PositionChanged event is not triggered, and PreviousPosition remains incorrect.
Description of Change
To correctly update the position and trigger the PositionChanged event, it update the PreviousPosition value correctly.
Validated the behavior in the following platforms
Issues Fixed
Fixes #29524
Output ScreenShot
29524-BeforeFix.mov
29524-AfterFix.mov