Skip to content

[Android] Fix incorrect CurrentItem after removing item from CarouselView with Loop=false - #39013

Merged
kubaflo merged 7 commits into
dotnet:candidate/11.0.1xx-sr2from
Dhivya-SF4094:fix-38821
Nov 12, 2026
Merged

kubaflo merged 7 commits into
dotnet:candidate/11.0.1xx-sr2from
Dhivya-SF4094:fix-38821

Conversation

@Dhivya-SF4094

@Dhivya-SF4094 Dhivya-SF4094 commented Sep 30, 2026 •

Copy link
Copy Markdown
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 Detail

On Android, CarouselView with Loop = false sets an incorrect CurrentItem after removing the currently selected item. When a new CurrentItem is explicitly assigned after the removal, the KeepItemsInView logic resets the carousel position to 0, causing the newly assigned CurrentItem to be overwritten by the first item.

Root Cause

  • On Android, removing the currently selected carousel item can result in two asynchronous state transitions: the adapter processes the item removal, and the handler subsequently dispatches a position update. When ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior for a removed current item is to reset the position to 0. This is correct when there is no subsequent CurrentItem change, but it can incorrectly override a newer CurrentItem assignment.
  • There is also a separate issue caused by the difference between the logical carousel position and the item that is actually rendered. After an item is removed, Carousel.Position can still contain the numeric index associated with the previous selection, while RecyclerView may have a different item centered
  • The regression was introduced by the KeepItemsInView position handling added in PR Fix for CarouselView doesnot scroll corresponding to ItemsUpdatingScrollMode when collection modified  #26608.

Description of Changes

  • The Android handler fix addresses both cases in MauiCarouselRecyclerView.cs:
  • Track CurrentItem updates as well as ScrollTo requests, so the deferred fallback does not overwrite a newer selection.
  • While a collection update is in progress, defer handling the CurrentItem scroll. Once the deferred callback runs, resolve the selected item’s index from the updated source, synchronize Position, and scroll to that index without animation.
  • If there is no newer selection, retain the existing fallback to the first item.

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed:

Fixes #38821

Screenshots

Before After
38821_Beforefix.mov
38821_Afterfix.mov

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39013

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39013"

@azure-pipelines

This comment has been minimized.

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Sep 30, 2026
@github-actions github-actions Bot added area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android labels Sep 30, 2026
@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Sep 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15517877 is running for android.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@azure-pipelines

This comment has been minimized.

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Expert Review — 1 findings

See inline comments for details.

MauiBot

This comment was marked as outdated.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) and removed s/agent-review-in-progress AI review is currently running for this PR labels Sep 30, 2026
@kubaflo

This comment has been minimized.

@github-actions

This comment has been minimized.

@kubaflo kubaflo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this one ready?

@vishnumenon2684

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@sheiksyedm
sheiksyedm marked this pull request as ready for review November 6, 2026 07:28
Copilot AI balanced review requested due to automatic review settings November 6, 2026 07:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Android carousel callbacks can drop newer selections during replacement or after a scroll request, leaving CurrentItem, Position, and the displayed item inconsistent.

2 open issues
What changed in this PR

This PR addresses Android CarouselView selection resets after removing the current item with Loop=false, preserving a subsequent CurrentItem assignment and synchronizing the rendered item.

Changes:

  • Tracks application selection updates separately from renderer synchronization.
  • Updates deferred removal and replacement handling to resolve the selected item’s position.
  • Adds UI tests for removal and replacement, plus Android device tests for selection changes inside CurrentItemChanged.
File Description
src/​Controls/​tests/​TestCases.Shared.Tests/​Tests/​Issues/​Issue38821.cs Verifies selection and centering after removal and replacement.
src/​Controls/​tests/​TestCases.HostApp/​Issues/​Issue38821.cs Adds a reproduction page with bound selection and collection-update controls.
src/​Controls/​tests/​DeviceTests/​Elements/​CarouselView/​CarouselViewTests.Android.cs Tests event-driven selection redirects with looping enabled and disabled.
src/​Controls/​src/​Core/​Handlers/​Items/​Android/​MauiCarouselRecyclerView.cs Coordinates deferred selection updates, position synchronization, and scrolling.

Review effort: Balanced

ScrollToPosition(carouselPosition);
}
}
else if (!scrollRequested && currentItemUpdated)
Comment on lines +1025 to +1027
if (_isInternalPositionUpdate)
{
return;
@kubaflo
kubaflo changed the base branch from main to candidate/11.0.1xx-sr2 November 12, 2026 19:56
@kubaflo
kubaflo merged commit 354c267 into dotnet:candidate/11.0.1xx-sr2 Nov 12, 2026
141 of 176 checks passed
kubaflo added a commit that referenced this pull request Nov 13, 2026
…View with Loop=false (#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR #26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes #38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 16, 2026
…View with Loop=false (#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR #26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes #38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 16, 2026
…View with Loop=false (#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR #26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes #38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 17, 2026
…View with Loop=false (#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR #26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes #38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…View with Loop=false (#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR #26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes #38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…View with Loop=false (#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR #26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes #38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…View with Loop=false (#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR #26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes #38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 19, 2026
…View with Loop=false (#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR #26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes #38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 22, 2026
…View with Loop=false (#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR #26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes #38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 23, 2026
…View with Loop=false (#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR #26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes #38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
@kubaflo kubaflo added this to the .NET 11 SR2 milestone Nov 24, 2026
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
…View with Loop=false (dotnet#39013)

<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Detail
On Android, CarouselView with Loop = false sets an incorrect CurrentItem
after removing the currently selected item. When a new CurrentItem is
explicitly assigned after the removal, the KeepItemsInView logic resets
the carousel position to 0, causing the newly assigned CurrentItem to be
overwritten by the first item.

### Root Cause

- On Android, removing the currently selected carousel item can result
in two asynchronous state transitions: the adapter processes the item
removal, and the handler subsequently dispatches a position update. When
ItemsUpdatingScrollModeis set to KeepItemsInView, the fallback behavior
for a removed current item is to reset the position to 0. This is
correct when there is no subsequent CurrentItem change, but it can
incorrectly override a newer CurrentItem assignment.
- There is also a separate issue caused by the difference between the
logical carousel position and the item that is actually rendered. After
an item is removed, Carousel.Position can still contain the numeric
index associated with the previous selection, while RecyclerView may
have a different item centered
- The regression was introduced by the KeepItemsInView position handling
added in PR dotnet#26608.

 
### Description of Changes

- The Android handler fix addresses both cases in
MauiCarouselRecyclerView.cs:
- Track CurrentItem updates as well as ScrollTo requests, so the
deferred fallback does not overwrite a newer selection.
- While a collection update is in progress, defer handling the
CurrentItem scroll. Once the deferred callback runs, resolve the
selected item’s index from the updated source, synchronize Position, and
scroll to that index without animation.
- If there is no newer selection, retain the existing fallback to the
first item.

### Validated the behaviour in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed:
Fixes dotnet#38821 
 
### Screenshots
| Before  | After  |
|---------|--------|
| <video
src="https://github.com/user-attachments/assets/99a0d676-d788-4cd2-9d82-43b7bcb6bbc4">
| <video
src="https://github.com/user-attachments/assets/eafaf5b2-cef8-4fbe-a08f-8e8ed730fad8">
|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
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 s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-review-in-progress AI review is currently running for this PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CurrentItem is incorrect after removing an item from the CarouselView (Loop = false)

6 participants