Skip to content

Conversation

SyedAbdulAzeemSF4852
Copy link
Contributor

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 :

  • When the item source is reloaded and items are added dynamically, updating the CurrentItem to one of the last items correctly changes the property, but the carousel fails to visually scroll to that position.

Root Cause:

  • When ScrollToPosition(carouselPosition) was called with a logical position like 0 (i.e., the CarouselView position), it scrolled to the raw adapter position 0. However, position 0 in the virtualized array represented the beginning of the full range, which was not the correct location for proper looping behavior. As a result, the center position was set to 0. Then, when attempting to scroll backward, the logic subtracted the target item index from this center position (0), leading to negative values.
  • This caused the scroll operation to fail, and no scrolling took place.

Description of Change

  • Updated GetGoToIndex in CarouselViewLoopManager.cs to correctly handle empty item sources and fix the calculation for determining the shortest scroll path in loop mode.
  • Modified MauiCarouselRecyclerView.cs to call UpdateInitialPosition after collection changes in loop mode, ensuring correct virtual positioning and proper centering of the carousel.

Issues Fixed

Fixes #23023

Validated the behaviour in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Output

Before After
Before.mov
After.mov

Copy link
Contributor

Hey there @@SyedAbdulAzeemSF4852! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Sep 18, 2025
@jsuarezruiz jsuarezruiz added platform/android area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Sep 18, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).


var diffToStart = currentCarouselPosition + (itemSourceCount - newPosition);
var diffToEnd = itemSourceCount - currentCarouselPosition + newPosition;
var diffToStart = (currentCarouselPosition - newPosition + itemSourceCount) % itemSourceCount;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also validate the position bounds, before use it:

if (newPosition < 0 || newPosition >= itemSourceCount)
    return -1;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz , As suggested, I validated the position bounds before using it.

App.Tap("Issue23023_ReloadItems");
App.Tap("Issue23023_ScrollToLastItem");

VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending snapshots in some platforms, running a build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz , I have added the pending snapshot for the Mac platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] CarouselView many issues with CurrentItem bindings
2 participants