Skip to content

[iOS] Fix: Carouselview restores stale Position over CurrentItem after off-screen ItemsSource Change - #36681

Merged
kubaflo merged 1 commit into
dotnet:inflight/currentfrom
SubhikshaSf4851:Fix-36602
Jul 20, 2026
Merged

kubaflo merged 1 commit into
dotnet:inflight/currentfrom
SubhikshaSf4851:Fix-36602

Conversation

@SubhikshaSf4851

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 whether this change resolves your issue. Thank you!

This pull request addresses an issue with CarouselView on iOS where replacing the ItemsSource and setting a new CurrentItem while the view is detached could result in the wrong item being displayed when reattached. The update ensures that the new CurrentItem is respected over any stale Position value after the ItemsSource is replaced while detached. Additionally, a new test is added to prevent regressions for this scenario.

This is a regression introduced by #36287, which added _lastSyncedPosition tracking and a reattach heuristic in CarouselViewController2.cs. That change unconditionally reset _lastSyncedPosition on every ItemsSource update — even while detached, when the Position/CurrentItem reset is skipped — causing the stale Position to be wrongly treated as an explicit user change on reattach and overriding a valid CurrentItem set on the replacement source.

Description of change

Bug Fixes:

Testing:

  • Added a new test CarouselViewHonorsCurrentItemOverStalePositionAfterDetachedItemsSourceReplacement in CarouselViewTests.iOS.cs to verify that replacing the ItemsSource and setting a new CurrentItem while detached works as expected after reattaching.
  • Introduced a helper method SetupBuilderForDetachedItemsSourceReplacement to configure handlers for the test scenario.

Issues Fixed

Fixes #36602

Tested the behavior in the following platforms

  • Windows
  • Android
  • iOS
  • Mac
Before Issue Fix After Issue Fix
BeforeFix36602-.mov
AfterFix36602-.mov

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Jul 20, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@SubhikshaSf4851! 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 the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jul 20, 2026
@sheiksyedm
sheiksyedm marked this pull request as ready for review July 20, 2026 14:29
@sheiksyedm
sheiksyedm requested a review from kubaflo July 20, 2026 14:29
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@kubaflo
kubaflo merged commit 33dd211 into dotnet:inflight/current Jul 20, 2026
10 of 43 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR10 milestone Jul 20, 2026
kubaflo pushed a commit that referenced this pull request Jul 22, 2026
…r off-screen ItemsSource Change (#36681)

<!-- Please keep the note below for people who 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 whether this change resolves your
issue. Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

This pull request addresses an issue with `CarouselView` on iOS where
replacing the `ItemsSource` and setting a new `CurrentItem` while the
view is detached could result in the wrong item being displayed when
reattached. The update ensures that the new `CurrentItem` is respected
over any stale `Position` value after the `ItemsSource` is replaced
while detached. Additionally, a new test is added to prevent regressions
for this scenario.

This is a regression introduced by #36287, which added
`_lastSyncedPosition` tracking and a reattach heuristic in
`CarouselViewController2.cs`. That change unconditionally reset
`_lastSyncedPosition` on every `ItemsSource` update — even while
detached, when the `Position`/`CurrentItem` reset is skipped — causing
the stale `Position` to be wrongly treated as an explicit user change on
reattach and overriding a valid `CurrentItem` set on the replacement
source.

### Description of change
**Bug Fixes:**

* Updated `CarouselViewController2.cs` to reset the tracked position
correctly when the `ItemsSource` is replaced, ensuring the new
`CurrentItem` is honored over a stale `Position` after reattaching the
view. This addresses the regression introduced in #36287.

**Testing:**

* Added a new test
`CarouselViewHonorsCurrentItemOverStalePositionAfterDetachedItemsSourceReplacement`
in `CarouselViewTests.iOS.cs` to verify that replacing the `ItemsSource`
and setting a new `CurrentItem` while detached works as expected after
reattaching.
* Introduced a helper method
`SetupBuilderForDetachedItemsSourceReplacement` to configure handlers
for the test scenario.

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36602 

### Tested the behavior in the following platforms

- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/881dbe8f-323b-49ba-894d-f23fd368651c">
| <video
src="https://github.com/user-attachments/assets/e55b5e56-4d74-4ad5-83b9-d63b41c6e503">
|

<!--

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Jul 28, 2026
…r off-screen ItemsSource Change (#36681)

<!-- Please keep the note below for people who 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 whether this change resolves your
issue. Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

This pull request addresses an issue with `CarouselView` on iOS where
replacing the `ItemsSource` and setting a new `CurrentItem` while the
view is detached could result in the wrong item being displayed when
reattached. The update ensures that the new `CurrentItem` is respected
over any stale `Position` value after the `ItemsSource` is replaced
while detached. Additionally, a new test is added to prevent regressions
for this scenario.

This is a regression introduced by #36287, which added
`_lastSyncedPosition` tracking and a reattach heuristic in
`CarouselViewController2.cs`. That change unconditionally reset
`_lastSyncedPosition` on every `ItemsSource` update — even while
detached, when the `Position`/`CurrentItem` reset is skipped — causing
the stale `Position` to be wrongly treated as an explicit user change on
reattach and overriding a valid `CurrentItem` set on the replacement
source.

### Description of change
**Bug Fixes:**

* Updated `CarouselViewController2.cs` to reset the tracked position
correctly when the `ItemsSource` is replaced, ensuring the new
`CurrentItem` is honored over a stale `Position` after reattaching the
view. This addresses the regression introduced in #36287.

**Testing:**

* Added a new test
`CarouselViewHonorsCurrentItemOverStalePositionAfterDetachedItemsSourceReplacement`
in `CarouselViewTests.iOS.cs` to verify that replacing the `ItemsSource`
and setting a new `CurrentItem` while detached works as expected after
reattaching.
* Introduced a helper method
`SetupBuilderForDetachedItemsSourceReplacement` to configure handlers
for the test scenario.

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36602 

### Tested the behavior in the following platforms

- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/881dbe8f-323b-49ba-894d-f23fd368651c">
| <video
src="https://github.com/user-attachments/assets/e55b5e56-4d74-4ad5-83b9-d63b41c6e503">
|

<!--

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Jul 29, 2026
…r off-screen ItemsSource Change (#36681)

<!-- Please keep the note below for people who 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 whether this change resolves your
issue. Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

This pull request addresses an issue with `CarouselView` on iOS where
replacing the `ItemsSource` and setting a new `CurrentItem` while the
view is detached could result in the wrong item being displayed when
reattached. The update ensures that the new `CurrentItem` is respected
over any stale `Position` value after the `ItemsSource` is replaced
while detached. Additionally, a new test is added to prevent regressions
for this scenario.

This is a regression introduced by #36287, which added
`_lastSyncedPosition` tracking and a reattach heuristic in
`CarouselViewController2.cs`. That change unconditionally reset
`_lastSyncedPosition` on every `ItemsSource` update — even while
detached, when the `Position`/`CurrentItem` reset is skipped — causing
the stale `Position` to be wrongly treated as an explicit user change on
reattach and overriding a valid `CurrentItem` set on the replacement
source.

### Description of change
**Bug Fixes:**

* Updated `CarouselViewController2.cs` to reset the tracked position
correctly when the `ItemsSource` is replaced, ensuring the new
`CurrentItem` is honored over a stale `Position` after reattaching the
view. This addresses the regression introduced in #36287.

**Testing:**

* Added a new test
`CarouselViewHonorsCurrentItemOverStalePositionAfterDetachedItemsSourceReplacement`
in `CarouselViewTests.iOS.cs` to verify that replacing the `ItemsSource`
and setting a new `CurrentItem` while detached works as expected after
reattaching.
* Introduced a helper method
`SetupBuilderForDetachedItemsSourceReplacement` to configure handlers
for the test scenario.

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36602 

### Tested the behavior in the following platforms

- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/881dbe8f-323b-49ba-894d-f23fd368651c">
| <video
src="https://github.com/user-attachments/assets/e55b5e56-4d74-4ad5-83b9-d63b41c6e503">
|

<!--

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Aug 7, 2026
…r off-screen ItemsSource Change (#36681)

<!-- Please keep the note below for people who 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 whether this change resolves your
issue. Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

This pull request addresses an issue with `CarouselView` on iOS where
replacing the `ItemsSource` and setting a new `CurrentItem` while the
view is detached could result in the wrong item being displayed when
reattached. The update ensures that the new `CurrentItem` is respected
over any stale `Position` value after the `ItemsSource` is replaced
while detached. Additionally, a new test is added to prevent regressions
for this scenario.

This is a regression introduced by #36287, which added
`_lastSyncedPosition` tracking and a reattach heuristic in
`CarouselViewController2.cs`. That change unconditionally reset
`_lastSyncedPosition` on every `ItemsSource` update — even while
detached, when the `Position`/`CurrentItem` reset is skipped — causing
the stale `Position` to be wrongly treated as an explicit user change on
reattach and overriding a valid `CurrentItem` set on the replacement
source.

### Description of change
**Bug Fixes:**

* Updated `CarouselViewController2.cs` to reset the tracked position
correctly when the `ItemsSource` is replaced, ensuring the new
`CurrentItem` is honored over a stale `Position` after reattaching the
view. This addresses the regression introduced in #36287.

**Testing:**

* Added a new test
`CarouselViewHonorsCurrentItemOverStalePositionAfterDetachedItemsSourceReplacement`
in `CarouselViewTests.iOS.cs` to verify that replacing the `ItemsSource`
and setting a new `CurrentItem` while detached works as expected after
reattaching.
* Introduced a helper method
`SetupBuilderForDetachedItemsSourceReplacement` to configure handlers
for the test scenario.

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36602 

### Tested the behavior in the following platforms

- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/881dbe8f-323b-49ba-894d-f23fd368651c">
| <video
src="https://github.com/user-attachments/assets/e55b5e56-4d74-4ad5-83b9-d63b41c6e503">
|

<!--

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Aug 12, 2026
…r off-screen ItemsSource Change (#36681)

<!-- Please keep the note below for people who 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 whether this change resolves your
issue. Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

This pull request addresses an issue with `CarouselView` on iOS where
replacing the `ItemsSource` and setting a new `CurrentItem` while the
view is detached could result in the wrong item being displayed when
reattached. The update ensures that the new `CurrentItem` is respected
over any stale `Position` value after the `ItemsSource` is replaced
while detached. Additionally, a new test is added to prevent regressions
for this scenario.

This is a regression introduced by #36287, which added
`_lastSyncedPosition` tracking and a reattach heuristic in
`CarouselViewController2.cs`. That change unconditionally reset
`_lastSyncedPosition` on every `ItemsSource` update — even while
detached, when the `Position`/`CurrentItem` reset is skipped — causing
the stale `Position` to be wrongly treated as an explicit user change on
reattach and overriding a valid `CurrentItem` set on the replacement
source.

**Bug Fixes:**

* Updated `CarouselViewController2.cs` to reset the tracked position
correctly when the `ItemsSource` is replaced, ensuring the new
`CurrentItem` is honored over a stale `Position` after reattaching the
view. This addresses the regression introduced in #36287.

**Testing:**

* Added a new test
`CarouselViewHonorsCurrentItemOverStalePositionAfterDetachedItemsSourceReplacement`
in `CarouselViewTests.iOS.cs` to verify that replacing the `ItemsSource`
and setting a new `CurrentItem` while detached works as expected after
reattaching.
* Introduced a helper method
`SetupBuilderForDetachedItemsSourceReplacement` to configure handlers
for the test scenario.

<!-- Enter description of the fix in this section -->

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36602

- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/881dbe8f-323b-49ba-894d-f23fd368651c">
| <video
src="https://github.com/user-attachments/assets/e55b5e56-4d74-4ad5-83b9-d63b41c6e503">
|

<!--

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 20, 2026
@sheiksyedm sheiksyedm modified the milestones: .NET 10 SR10, .NET 10 SR11 Aug 26, 2026

This branch had an error being deployed

1 failed deployment
copilot-pat-pool — a759204b Deployed Jul 20, 2026 by SubhikshaSf4851 via pre_activation #866
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView collectionview-cv2 community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[inflight regression] iOS CarouselView restores stale Position over CurrentItem after off-screen ItemsSource replacement

4 participants