Repository navigation
[Android] Fix incorrect CurrentItem after removing item from CarouselView with Loop=false - #39013
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39013Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39013" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Note 🔍
|
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 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) |
| if (_isInternalPositionUpdate) | ||
| { | ||
| return; |
354c267
into
dotnet:candidate/11.0.1xx-sr2
…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>
…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>
…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>
…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>
…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>
…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>
…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>
…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>
…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>
…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>
…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>

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
Description of Changes
Validated the behaviour in the following platforms
Issues Fixed:
Fixes #38821
Screenshots
38821_Beforefix.mov
38821_Afterfix.mov