Skip to content

[Android]Fix KeepItemsInView mode not scrolling to first item on collection update - #39491

Merged
kubaflo merged 3 commits into
dotnet:candidate/11.0.1xx-sr2from
SuthiYuvaraj:Fix-26810
Nov 12, 2026
Merged

kubaflo merged 3 commits into
dotnet:candidate/11.0.1xx-sr2from
SuthiYuvaraj:Fix-26810

Conversation

@SuthiYuvaraj

@SuthiYuvaraj SuthiYuvaraj commented Oct 20, 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 Details

When the ItemsUpdatingScrollMode is set to KeepItemsInView, the items doesnot scroll to the first item , it maintains the current item

Root Cause

In the MauiRecyclerView, the data change observer is paused for KeepItemsInView in ItemsUpdatingScrollMode to maintain the first position of the item.

Description of Change

We need to observe the data changes for the KeepItemsInView option, as there may be cases where the item might not remain in view.The issue is fixed by restarting the data change observer in MauiRecyclerView.

Reference PR : #27153

Issues Fixed

Fixes #26810
Fixes #28006
Fixes #29153
Fixes #29145

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Output Screenshot

Before Issue Fix After Issue Fix
Screen.Recording.2026-10-14.at.6.58.26.PM.mov
Screen.Recording.2026-10-20.at.3.45.06.PM.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 -- 39491

Or

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

@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 Oct 20, 2026
@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 20, 2026
@kubaflo

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions

This comment has been minimized.

@SuthiYuvaraj SuthiYuvaraj changed the title [WIP][Android]Fix KeepItemsInView mode not scrolling to first item on collection update [Android]Fix KeepItemsInView mode not scrolling to first item on collection update Oct 22, 2026
@sheiksyedm
sheiksyedm marked this pull request as ready for review October 22, 2026 11:19
Copilot AI balanced review requested due to automatic review settings October 22, 2026 11:19

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

The observer resets scrolling for non-add updates and is not reattached after runtime item-template replacement.

2 open issues
What changed in this PR

Updates Android CollectionView scrolling so KeepItemsInView returns to the first item after collection updates, while preserving CarouselView’s separate position handling.

Changes:

  • Enables observer-driven first-item scrolling and updates the scroll-mode documentation.
  • Makes invalid observable-source lookups return null in both Android implementations.
  • Adds horizontal and vertical UI scenarios, adjusts existing scroll-mode expectations, and adds index-boundary device tests.
File Description
src/​Controls/​tests/​TestCases.Shared.Tests/​Tests/​Issues/​Issue26810Vertical.cs Adds vertical scroll-mode UI coverage.
src/​Controls/​tests/​TestCases.Shared.Tests/​Tests/​Issues/​Issue26810.cs Adds horizontal scroll-mode UI coverage.
src/​Controls/​tests/​TestCases.Shared.Tests/​Tests/​Issues/​CollectionViewUITests.CollectionViewItemsUpdatingScrollMode.cs Updates Android insertion expectations.
src/​Controls/​tests/​TestCases.HostApp/​Issues/​Issue26810Vertical.cs Provides the vertical test page.
src/​Controls/​tests/​TestCases.HostApp/​Issues/​Issue26810.cs Provides shared test controls and the horizontal page.
src/​Controls/​tests/​DeviceTests/​Elements/​CollectionView/​CollectionViewTests.Android.cs Tests invalid indices and cleared collections.
src/​Controls/​src/​Core/​Items/​ItemsUpdatingScrollMode.cs Revises KeepItemsInView documentation.
src/​Controls/​src/​Core/​Handlers/​Items/​Android/​MauiRecyclerView.cs Enables observation and first-item scrolling outside CarouselView.
src/​Controls/​src/​Core/​Handlers/​Items/​Android/​ItemsSources/​ObservableItemsSource.cs Returns null for invalid item lookups.
src/​Compatibility/​Core/​src/​Android/​CollectionView/​ObservableItemsSource.cs Applies matching lookup behavior to compatibility code.

Review effort: Balanced

}

if (ItemsView.ItemsUpdatingScrollMode == ItemsUpdatingScrollMode.KeepItemsInView)
if (ItemsView is CarouselView && ItemsView.ItemsUpdatingScrollMode == ItemsUpdatingScrollMode.KeepItemsInView)
Comment on lines +1124 to +1125
ScrollTo(new ScrollToRequestEventArgs(0, -1,
Microsoft.Maui.Controls.ScrollToPosition.Start, false));
@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.

Could you please check the ai's suggestions?

kubaflo added a commit that referenced this pull request Nov 17, 2026
…40227)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, branched from
`41458556cf5d13573a632b83f89072f8badfb205`. No rebase, retarget, product
change, or merge is included.

### Description of Change

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

Correct the stale `KeepItemsInView` UI-test contract exposed by #40116.
The [CollectionView
documentation](https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/collectionview/scrolling.md#control-scroll-position-when-new-items-are-added)
and current enum XML documentation specify keeping the **first item in
the list** displayed. #39491 and #39493 intentionally implement that
behavior. The remaining Apple test instead expected the previously
visible middle item; the Android branch only checked that this old item
disappeared.

Use the same positive assertions on Android, iOS and MacCatalyst,
retaining the existing Windows exclusion and CollectionView shard.
Verify the initial middle item is actually displayed, insert once, and
positively assert that `cover1.jpg, 0` is displayed. Scroll away again
and verify the new middle identity (`photo.jpg, 9`), then perform the
remaining 24 insertions and positively assert the first item again. This
preserves 25 total updates and prevents the second check from passing
merely because the first insertion already scrolled to the top.

The existing sample inserts at `(Count / 2) - 1`, **not** at index zero;
the first item's identity remains unchanged. No sample IDs, product
behavior, `KeepScrollOffset`, `KeepLastItemInView`, timeouts, retries,
skips, screenshots, tolerances, or CI configuration are changed.
Upstream searches found the existing product fixes above but no
competing test-contract correction.

**Native validation**

Used the original `ui-tests-samples-coreclr` HostApp from
[maui-pr-uitests
1678816](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1678816),
source `fd2f3ce40199b5c48e31a1814a23919f41f6c3d3`, on an isolated iPhone
11 Pro **CoreSimulator iOS 26.5**. The gallery, data source, template,
Apple scroll helper, and both Apple layout implementations have no
source diff between that CI source and this branch's candidate base.
This does not claim the entire binary tree is identical. HostApp
executable SHA-256:
`895101edc9254a6e235051f77cd2bc8e72d4646477b1ed4b308d8de86392396c`.

| Native oracle on the unchanged CI app | Result |
| --- | --- |
| Original Apple test, 25 insertions, old middle-item expectation |
Failed at final `WaitForElement("Vegetables.jpg, 10")`, reproducing CI
(42 s) |
| Corrected positive first-item test | Passed 3/3 (29 s, 31 s, 29 s) |
| Negative mutation: expect the old middle item after the first
insertion | Failed at that wrong-target oracle (25 s) |
| Restored corrected test after the negative mutation | Passed 2/2;
included in the 3/3 above |

Exact test command for the first corrected run (passed 1/1; repeated
with separate result/log paths for the other runs):

```sh
DEVICE_UDID=05DEC405-3AC9-4F2E-8DBC-8B75A0CF9F4C PLATFORM_VERSION=26.5 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/appium-corrected.log dotnet test artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net11.0/Controls.TestCases.iOS.Tests.dll --filter 'FullyQualifiedName~KeepItemsInView' --logger 'trx;LogFileName=corrected.trx' --results-directory /Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/native-corrected
```

The native HostApp was **not rebuilt** using the locally installed Xcode
27.2 or SDK-check bypasses. Only the platform-neutral net11.0 NUnit
runner was rebuilt using installed .NET SDK 11.0.100. The artifact route
deliberately avoids the local HostApp runner's source rebuild and
shutdown of other sessions' simulators. An initial overly specific
discovery filter selected zero tests; it was corrected to the command
above before collecting these outcomes.

Exact compilation/formatting commands and results:

```sh
# Passed: iOS NUnit runner, final corrected source.
dotnet msbuild src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Android NUnit runner compilation; not an Android native execution.
dotnet msbuild src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Catalyst NUnit runner compilation; not a Catalyst native execution.
dotnet msbuild src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/CollectionViewUITests.CollectionViewItemsUpdatingScrollMode.cs --verify-no-changes --verbosity quiet
# Passed.
git diff --check
```

Native Android and MacCatalyst execution and full-suite CI are not
claimed. No duplicate candidate-wide CI run was queued; candidate-wide
coverage remains coordinated separately.

### 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. -->

Relates to #40116, #39491, and #39493. These references are
intentionally non-closing; this fixes the test contract, not the
underlying product issues.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 17, 2026
…ng (#40258)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, based on
`dca0930d7167052b18c0fa25b1995fa416c2bb06`. No merge, retarget, rebase,
or manual CI/review request is included.

### Description of Change

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

Make the `Github5623` incremental-loading sample explicitly use
`KeepScrollOffset`. Its implicit `KeepItemsInView` default now
intentionally scrolls to the first item after an insertion (#39491).
That behavior is correct for that mode, but inappropriate for this
sample's continuous user scrolling through asynchronously appended
pages. #40227's documented first-item contract and the production
implementation remain intact.

The original API30 `Github5623(Android).CollectionViewInfiniteScroll`
oracle reproduced the candidate timeout at
`AppiumTouchActions.ScrollTo:333` / original test line 27. Separate
native diagnostics observed successful page appends `10 -> 20 -> 30 ->
40`, each immediately followed by a native zero-delta callback with the
first cell back at index 0/top 0. These rewinds explain the large
cumulative managed scroll offset despite low visible indexes.
Temporarily removing that native rewind as a **diagnostic control only**
eliminated the resets. The native control and all diagnostic code were
then restored and hash-verified before committing.

The committed change is exactly one XAML attribute. The original NUnit
method, discovery of item `12` by actual user gestures, random 20-319
item heights, `MeasureAllItems`, threshold 25, initial/page size 10,
loading implementation, original 15-second `ScrollTo` deadline, waits,
assertions, retries, categories, and screenshots are unchanged. This is
a sample contract correction, not a production rollback or a weakened
test.

Upstream open/recently merged PR searches covered `Github5623`, infinite
scrolling, `KeepItemsInView`, and `KeepScrollOffset`, together with the
exact sample file history. They identified #39491 and #40227 but no
competing sample repair.

**Native evidence**

Used one task-owned API30 Google APIs ARM64 Nexus 5X emulator, 1080x1920
at 420 dpi, with .NET SDK 11.0.100/runtime 11.0.0, source-built Release
HostApp, embedded assemblies, and the original Android NUnit assembly.
Appium transport alone was adapted locally to private ports
4793/8293/7893 and the owned emulator; that adaptation is not committed.
No physical Apple device or host macOS XCTest automation was used.

| Phase | Actual cases | Result |
| --- | --- | --- |
| Unchanged original sample/oracle | 1 | Failed: exact scrolling-to-12
timeout, 18.233251 s |
| Instrumented native trigger-removal control, not the published fix | 1
| Passed, 7.563766 s; appends retained without rewind |
| Non-instrumented sample-only fix | 3 | Passed: 10.791304 / 8.946879 /
8.947579 s |
| Revert only the sample attribute, restore and rebuild original sources
| 1 | Failed: same scrolling-to-12 timeout, 17.930881 s |
| Restore fix, rebuild immutable
`026e646e5f820804ca655813a9a5c0e83e40e115` | 3 | Passed: 8.922002 /
11.637289 / 10.590518 s |
| Unchanged original `TestCategory=CollectionView2` selector on that
pushed immutable head | 77 | **77 passed, 0 failed, 0 skipped**;
original infinite-scroll case passed in 7.278173 s |

Raw TRX and NUnit XML were checked independently and retained for every
invocation. A separate diagnostic run with the original rewind still
enabled passed in 16.054472 s and is **not** counted as a
non-instrumented baseline pass. Five initial zero-test selector
invocations and one Appium argument-quoting setup failure are retained
separately; none establishes an original-oracle outcome.

Immutable-head APK SHA-256:
`1b3cf5c30f5c001919874e540f52183cf41d346a4b7b2bcfa8ab4b1cd687b9f8`.

**Limits:** the local causal chain proves the sample repair on API30
ARM64/.NET 11 GA, and the completed exact-source API30 CI suite below
now supplies CI-servicing confirmation for the original 77-case Android
suite. Other-platform and whole-pipeline clearance are not claimed. The
supplied newest exact-target CI case was green; this PR does not claim
that the latest target was red or that the unrelated managed-unit
correction caused the failure. Candidate-wide CI remains
parent-coordinated.

**CI validation and remaining limits (2026-11-14 UTC snapshot)**

The live PR remains at head `026e646e5f820804ca655813a9a5c0e83e40e115`,
candidate base `dca0930d7167052b18c0fa25b1995fa416c2bb06`, and synthetic
merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. The human-issued
review, rebase, and pipeline requests on November 14 did not change
those source identities.

The earlier [maui-pr
1681455](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681455)
and [maui-pr-uitests
1681457](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681457)
were **canceled**, not complete passing runs. Before cancellation, the
four managed-unit Helix jobs completed and all **50 product work-item
XML reports** were audited, excluding controller work items, with no
named failures, assembly errors, or XML/count gaps. In each of
Debug/Release on macOS ARM64/Windows x64, Core recorded **1,125 passed,
0 skipped** and SourceGen **733 passed, 53 existing gated skips**. Those
skips are not passes; configuration counts are not summed into a
unique-test total. This source does not include the separate metadata
correction in #40252. Completed unit XML evidence remains valid despite
cancellation; it does not establish a full build, pack, integration, UI,
or device-test pass.

The human-requested replacement runs use the **same synthetic merge**.
They were initially confirmed **in progress**; the later terminal
UI/device status and remaining main-pipeline coverage are recorded
below:

| Pipeline | Existing replacement run | Queued (UTC) |
| --- | --- | --- |
| `maui-pr` |
[1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489)
| 16:45:42 |
| `maui-pr-uitests` |
[1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
| 16:45:45 |
| `maui-pr-devicetests` |
[1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
| 16:45:48 |

Reuse those runs; no additional pipelines or reviews were queued for
this description update. The native causal chain and original local **77
passed / 0 failed / 0 skipped** result above remain separate evidence,
not replacement-CI results.

The human-requested `maui-copilot` review gate
[16033607](https://dev.azure.com/DevDiv/DevDiv/_build/results?buildId=16033607)
is
**[INCONCLUSIVE](#40258 (comment):
provisioning stopped before verifying/checking out the PR head,
establishing a baseline, or running tests. Its trusted runner source
`e1140933230eabacbaf6412c0b8d80ece38f2d48` is not the tested PR source.
Original Azure raw log 12 contains 32 physical lines; lines 13, 21, and
29 repeat the protection refusal across the three existing setup
attempts: "The new servicing/staging target must have branch protection
before credential-bearing provisioning can run. Refusing to switch."
GitHub independently reports `candidate/11.0.1xx-sr2` as
`protected=false`.

This gate supplied **no test execution or causal-baseline result**. It
is not a test-red verdict or evidence against the sample fix. Deploying
the required candidate branch protection is a **maintainer action**; do
not bypass or modify the guard. Full replacement-CI outcomes and a
successfully provisioned review gate remain outstanding.

**Later CI/review evidence (2026-11-14 UTC)**

[Expert review
5905946810](#40258 (review))
reviewed exact head `026e646e5f820804ca655813a9a5c0e83e40e115` and
reported **zero findings**. Its state is `COMMENTED`, not human approval
or a successful runtime gate. Candidate protection is still `false`; the
provisioning gate described above remains blocked.

In [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
at the same `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` merge, the
**CoreCLR device-test build failed before runtime execution**. Original
raw log 63 records nine CA1416 diagnostics while compiling Essentials
`net11.0-ios27.0`: three deprecated `UIGraphics` calls in
`MediaPicker/ImageProcessor.ios.cs` and six availability calls in
`Passkeys/Passkeys.ios.cs`. The original binlog confirms those nine
diagnostics plus one outer `BuildFailed`, not independent faults in
every downstream project. Three dependent CoreCLR runtime stages were
skipped, leaving a coverage gap.

Those two Essentials source files are byte-identical on the target and
candidate. The actual candidate control [device run
1681310](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681310),
source `77a87edc03aa2728d7e0a51050da0e424a82c801`, completed the CoreCLR
build successfully with zero errors (original raw log 67). This build
failure is unrelated to the sample's one XAML attribute; the precise
analyzer-input divergence remains **unproven**. No speculative
availability/source fix or analyzer suppression is proposed.

Completed portions of [replacement UI run
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490),
on the same merge, supply separate unchanged MacCatalyst evidence:
CollectionView7 run **46901196** recorded **52 passed, 0 skipped**,
including both #31899 header/footer cases, with no retry; mixed drag
shard run **46901170** recorded **57 passed, 1 existing skip**,
including the #12060 and #28416 cases, with no retry. These are not
evidence of a causal MacCatalyst repair by this Android
incremental-sample change.

The MacCatalyst Navigation shard still has **two failures on both the
original attempt and existing retry**: #21814 receives an empty
navigation-event string, and #23902 receives "NavigatedTo called 2
times" instead of 3. Original raw log 3790 and publisher log 3792
correlate to run **46901248** (**85 passed, 2 failed, 1 skipped**);
failure details are
[#21814](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087)
and
[#23902](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086).
These repeat separately observed candidate/branch failures and are not
attributed to the unrelated sample delta.

The replacement Android `Github5623`/original 77-case CollectionView2 CI
result is published and passed on its first attempt, as detailed below.
Overall UI run **1681490** and device run **1681491** have completed
failed; main run **1681489** remains in progress with passing
Build/Pack/Unit stages and incomplete integration coverage. Keep the
original local causal/full-77 evidence distinct from completed CI shard
results, recovered initial failures, and remaining pipeline outcomes. No
new queues, review replies, source changes, or protection changes were
made.

**Completed exact-source Android CI (2026-11-14 UTC)**

The original API30 CollectionView2 suite completed in [maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
at synthetic merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` (PR head
`026e646e5f820804ca655813a9a5c0e83e40e115`, candidate base
`dca0930d7167052b18c0fa25b1995fa416c2bb06`). [Original run
46901428](https://dev.azure.com/dnceng-public/public/_TestManagement/Runs?runId=46901428&_a=runCharts)
recorded **77 passed, 0 failed, 0 skipped on the first attempt**. The
actual [Github5623(Android).CollectionViewInfiniteScroll result
100042](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901428/Results/100042)
passed in **9,353 ms**, without a harness retry.

Original Azure [raw log
4026](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4026)
contains 1,254 physical lines and the successful 77-pass summary, with
no failed case or harness retry. [Publisher log
4028](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4028)
links those exact 77 results to run 46901428. All 77 automated names and
their multiplicities match actual-candidate original run 46895912; the
selector, original oracle, and 15-second scroll deadline were not
reduced or changed. This closes the previously recorded local
ARM64/GA-versus-CI-servicing runtime gap **for this original Android
suite only**; the local causal chain remains independently documented
above.

This is not a whole-pipeline or other-platform clearance. The two
MacCatalyst Navigation failures above remain. A separate MacCatalyst
[#25074
result](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228)
fails `ButtonResizesWhenTitleOrImageChangesAltered.png` with **1.14%
difference on both the original attempt and existing retry**; it is
unrelated to this sample delta, not an Android-oracle failure. The
CoreCLR availability-build failure and skipped-runtime coverage gap in
device run 1681491 remain; that overall device run has completed
**failed**, as has UI run 1681490. Candidate protection is still
`false`, so the runtime review gate remains blocked despite the
exact-head zero-findings expert review. Main run 1681489 has passing
Build/Pack/Unit stages, but its incomplete Integration stage prevents a
whole-main pass. The full terminal UI and measured integration scopes
are detailed below. No new queues, review replies, source changes, or
protection changes were made.

**Terminal UI audit and remaining validation (2026-11-14 UTC)**

[maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
has completed **failed** at exact merge
`b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. All **129 original UI task
raw logs**, their own publishers, and **129 actual final result sets**
were audited. Final published records across platforms/categories are
**14,907 passed, 302 NotExecuted, 3 failed**. These are execution
records, **not unique methods or first-attempt green results**. Nineteen
eventually successful tasks retain **71 original failed records** in
their raw logs; retry recovery does not erase those failures or
establish causal repairs. Every raw failure method name appears in a
corresponding final run, but this is a method-name presence check, not a
claim of fully qualified oracle identity equivalence.

The only three final failures are the MacCatalyst cases already
documented: [#25074's 1.14% altered-button
snapshot](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228),
[#23902's two-versus-three navigation
count](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086),
and [#21814's empty navigation-event
text](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087).
The original Android API30 CollectionView2 suite above remains **77
passed, 0 failed, 0 skipped on its first attempt, with no harness
retry**; the full terminal audit independently preserves its original
log 4026, publisher 4028, and run 46901428. The unrelated Mac failures
do not invalidate that exact Android result.

[maui-pr
1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489),
on the same merge, now has completed passing **Build, Pack, and Helix
Unit Test stages**, but **the whole pipeline is not yet passed**. Only
**20 of 23 original integration tasks** have completed measured
summaries: **311 passed, 10 existing skips, 0 failed** in those
completed tasks. Three tasks remain unmeasured/in progress:
`mac_buildtemplate_previous_tests`, Windows `Build`, and Windows
`Blazor`. Their absent results are not zero failures or passes.

Terminal [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
remains **failed**. Its **31 available product XML reports** contain
**22,318 passed, 2 existing Windows Border failures, 549 existing
skips**, with available per-assembly counts checked and no
assembly-error/count gaps. Skip identities, reasons, and multiplicities
match the candidate; counts span available execution/configuration
records, not unique methods. The nine-CA1416 CoreCLR compile failure and
three skipped dependent runtime stages remain a separate coverage gap:
available XML results do not certify the missing CoreCLR matrix.

The PR head, candidate base, and synthetic merge are unchanged.
Candidate protection remains `false`, the provisioning review gate
remains blocked, and zero-findings expert review is still not human
approval or runtime-gate success. No source changes, pushes, new queues,
review replies, or protection changes were made for this validation
update.

**Exact validation commands and results**

```sh
# Passed: Android-only repository build tasks.
dotnet build ./Microsoft.Maui.BuildTasks.slnf -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:BuildTaskOnlyBuild=true -v:q -nologo

# Passed for original, diagnostic control, fixed, reverted, restored, and immutable-head builds.
dotnet build src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj -c Release -f net11.0-android -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:RuntimeIdentifier=android-arm64 -p:EmbedAssembliesIntoApk=true -v:q -nologo

# Passed: original Android NUnit runner, with private transport only.
dotnet build src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -v:q -nologo

# Same command for each original-oracle phase; $resultdir selected a separate retained phase/attempt directory.
# Results are the actual cases in the phase table above; no automatic test retry was added.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE="$resultdir/appium.log" dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'Name=CollectionViewInfiniteScroll' --logger 'trx;LogFileName=original.trx' --results-directory "$resultdir" -v:q -nologo -- "NUnit.TestOutputXml=$resultdir/nunit"

# Passed: original 77-case selector, after pushing and verifying the exact immutable head.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/appium.log dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'TestCategory=CollectionView2' --logger 'trx;LogFileName=collectionview2.trx' --results-directory /Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2 -v:q -nologo -- NUnit.TestOutputXml=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/nunit

# Passed.
xmllint --noout src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml
# Passed.
git diff --check

# Not completed: bounded/stopped during full-solution loading without output; no formatting pass claimed.
# Only XAML changed; native XAML compilation and XML syntax checks above passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml --verify-no-changes --verbosity quiet
```

Direct source build/install/NUnit commands mirror the existing Cake
UI-test recipe and deliberately avoid the local wrapper's global ADB
restart/recovery behavior in this shared environment. Pre-existing
emulators and their ADB server were preserved.

### 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. -->

Relates to #40116, #39491, and #40227. These references are
intentionally non-closing; this corrects the incremental-loading
sample's scroll-mode contract.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…ection update (#39491)

<!-- 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 Details

When the `ItemsUpdatingScrollMode` is set to `KeepItemsInView,` the
items doesnot scroll to the first item , it maintains the current item

### Root Cause

In the `MauiRecyclerView`, the data change observer is paused for
`KeepItemsInView` in `ItemsUpdatingScrollMode` to maintain the first
position of the item.

### Description of Change

We need to observe the data changes for the `KeepItemsInView` option, as
there may be cases where the item might not remain in view.The issue is
fixed by restarting the data change observer in `MauiRecyclerView`.

### Reference PR : #27153 

### Issues Fixed
Fixes #26810 
Fixes #28006
Fixes #29153
Fixes #29145 

### Tested the behaviour in the following platforms
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

### Output Screenshot
Before Issue Fix | After Issue Fix |
|----------|----------|
|<video width="200" height="200" alt="Before Fix video"
src="https://github.com/user-attachments/assets/8adbd870-9c8f-4ac2-bdf2-93301ef0e073">|<video
width="200" height="200" alt="After Fix video"
src="https://github.com/user-attachments/assets/5edb1a05-2a81-46ba-bb1f-353530b4fbc9">|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…40227)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, branched from
`41458556cf5d13573a632b83f89072f8badfb205`. No rebase, retarget, product
change, or merge is included.

### Description of Change

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

Correct the stale `KeepItemsInView` UI-test contract exposed by #40116.
The [CollectionView
documentation](https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/collectionview/scrolling.md#control-scroll-position-when-new-items-are-added)
and current enum XML documentation specify keeping the **first item in
the list** displayed. #39491 and #39493 intentionally implement that
behavior. The remaining Apple test instead expected the previously
visible middle item; the Android branch only checked that this old item
disappeared.

Use the same positive assertions on Android, iOS and MacCatalyst,
retaining the existing Windows exclusion and CollectionView shard.
Verify the initial middle item is actually displayed, insert once, and
positively assert that `cover1.jpg, 0` is displayed. Scroll away again
and verify the new middle identity (`photo.jpg, 9`), then perform the
remaining 24 insertions and positively assert the first item again. This
preserves 25 total updates and prevents the second check from passing
merely because the first insertion already scrolled to the top.

The existing sample inserts at `(Count / 2) - 1`, **not** at index zero;
the first item's identity remains unchanged. No sample IDs, product
behavior, `KeepScrollOffset`, `KeepLastItemInView`, timeouts, retries,
skips, screenshots, tolerances, or CI configuration are changed.
Upstream searches found the existing product fixes above but no
competing test-contract correction.

**Native validation**

Used the original `ui-tests-samples-coreclr` HostApp from
[maui-pr-uitests
1678816](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1678816),
source `fd2f3ce40199b5c48e31a1814a23919f41f6c3d3`, on an isolated iPhone
11 Pro **CoreSimulator iOS 26.5**. The gallery, data source, template,
Apple scroll helper, and both Apple layout implementations have no
source diff between that CI source and this branch's candidate base.
This does not claim the entire binary tree is identical. HostApp
executable SHA-256:
`895101edc9254a6e235051f77cd2bc8e72d4646477b1ed4b308d8de86392396c`.

| Native oracle on the unchanged CI app | Result |
| --- | --- |
| Original Apple test, 25 insertions, old middle-item expectation |
Failed at final `WaitForElement("Vegetables.jpg, 10")`, reproducing CI
(42 s) |
| Corrected positive first-item test | Passed 3/3 (29 s, 31 s, 29 s) |
| Negative mutation: expect the old middle item after the first
insertion | Failed at that wrong-target oracle (25 s) |
| Restored corrected test after the negative mutation | Passed 2/2;
included in the 3/3 above |

Exact test command for the first corrected run (passed 1/1; repeated
with separate result/log paths for the other runs):

```sh
DEVICE_UDID=05DEC405-3AC9-4F2E-8DBC-8B75A0CF9F4C PLATFORM_VERSION=26.5 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/appium-corrected.log dotnet test artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net11.0/Controls.TestCases.iOS.Tests.dll --filter 'FullyQualifiedName~KeepItemsInView' --logger 'trx;LogFileName=corrected.trx' --results-directory /Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/native-corrected
```

The native HostApp was **not rebuilt** using the locally installed Xcode
27.2 or SDK-check bypasses. Only the platform-neutral net11.0 NUnit
runner was rebuilt using installed .NET SDK 11.0.100. The artifact route
deliberately avoids the local HostApp runner's source rebuild and
shutdown of other sessions' simulators. An initial overly specific
discovery filter selected zero tests; it was corrected to the command
above before collecting these outcomes.

Exact compilation/formatting commands and results:

```sh
# Passed: iOS NUnit runner, final corrected source.
dotnet msbuild src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Android NUnit runner compilation; not an Android native execution.
dotnet msbuild src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Catalyst NUnit runner compilation; not a Catalyst native execution.
dotnet msbuild src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/CollectionViewUITests.CollectionViewItemsUpdatingScrollMode.cs --verify-no-changes --verbosity quiet
# Passed.
git diff --check
```

Native Android and MacCatalyst execution and full-suite CI are not
claimed. No duplicate candidate-wide CI run was queued; candidate-wide
coverage remains coordinated separately.

### 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. -->

Relates to #40116, #39491, and #39493. These references are
intentionally non-closing; this fixes the test contract, not the
underlying product issues.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…ng (#40258)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, based on
`dca0930d7167052b18c0fa25b1995fa416c2bb06`. No merge, retarget, rebase,
or manual CI/review request is included.

### Description of Change

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

Make the `Github5623` incremental-loading sample explicitly use
`KeepScrollOffset`. Its implicit `KeepItemsInView` default now
intentionally scrolls to the first item after an insertion (#39491).
That behavior is correct for that mode, but inappropriate for this
sample's continuous user scrolling through asynchronously appended
pages. #40227's documented first-item contract and the production
implementation remain intact.

The original API30 `Github5623(Android).CollectionViewInfiniteScroll`
oracle reproduced the candidate timeout at
`AppiumTouchActions.ScrollTo:333` / original test line 27. Separate
native diagnostics observed successful page appends `10 -> 20 -> 30 ->
40`, each immediately followed by a native zero-delta callback with the
first cell back at index 0/top 0. These rewinds explain the large
cumulative managed scroll offset despite low visible indexes.
Temporarily removing that native rewind as a **diagnostic control only**
eliminated the resets. The native control and all diagnostic code were
then restored and hash-verified before committing.

The committed change is exactly one XAML attribute. The original NUnit
method, discovery of item `12` by actual user gestures, random 20-319
item heights, `MeasureAllItems`, threshold 25, initial/page size 10,
loading implementation, original 15-second `ScrollTo` deadline, waits,
assertions, retries, categories, and screenshots are unchanged. This is
a sample contract correction, not a production rollback or a weakened
test.

Upstream open/recently merged PR searches covered `Github5623`, infinite
scrolling, `KeepItemsInView`, and `KeepScrollOffset`, together with the
exact sample file history. They identified #39491 and #40227 but no
competing sample repair.

**Native evidence**

Used one task-owned API30 Google APIs ARM64 Nexus 5X emulator, 1080x1920
at 420 dpi, with .NET SDK 11.0.100/runtime 11.0.0, source-built Release
HostApp, embedded assemblies, and the original Android NUnit assembly.
Appium transport alone was adapted locally to private ports
4793/8293/7893 and the owned emulator; that adaptation is not committed.
No physical Apple device or host macOS XCTest automation was used.

| Phase | Actual cases | Result |
| --- | --- | --- |
| Unchanged original sample/oracle | 1 | Failed: exact scrolling-to-12
timeout, 18.233251 s |
| Instrumented native trigger-removal control, not the published fix | 1
| Passed, 7.563766 s; appends retained without rewind |
| Non-instrumented sample-only fix | 3 | Passed: 10.791304 / 8.946879 /
8.947579 s |
| Revert only the sample attribute, restore and rebuild original sources
| 1 | Failed: same scrolling-to-12 timeout, 17.930881 s |
| Restore fix, rebuild immutable
`026e646e5f820804ca655813a9a5c0e83e40e115` | 3 | Passed: 8.922002 /
11.637289 / 10.590518 s |
| Unchanged original `TestCategory=CollectionView2` selector on that
pushed immutable head | 77 | **77 passed, 0 failed, 0 skipped**;
original infinite-scroll case passed in 7.278173 s |

Raw TRX and NUnit XML were checked independently and retained for every
invocation. A separate diagnostic run with the original rewind still
enabled passed in 16.054472 s and is **not** counted as a
non-instrumented baseline pass. Five initial zero-test selector
invocations and one Appium argument-quoting setup failure are retained
separately; none establishes an original-oracle outcome.

Immutable-head APK SHA-256:
`1b3cf5c30f5c001919874e540f52183cf41d346a4b7b2bcfa8ab4b1cd687b9f8`.

**Limits:** the local causal chain proves the sample repair on API30
ARM64/.NET 11 GA, and the completed exact-source API30 CI suite below
now supplies CI-servicing confirmation for the original 77-case Android
suite. Other-platform and whole-pipeline clearance are not claimed. The
supplied newest exact-target CI case was green; this PR does not claim
that the latest target was red or that the unrelated managed-unit
correction caused the failure. Candidate-wide CI remains
parent-coordinated.

**CI validation and remaining limits (2026-11-14 UTC snapshot)**

The live PR remains at head `026e646e5f820804ca655813a9a5c0e83e40e115`,
candidate base `dca0930d7167052b18c0fa25b1995fa416c2bb06`, and synthetic
merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. The human-issued
review, rebase, and pipeline requests on November 14 did not change
those source identities.

The earlier [maui-pr
1681455](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681455)
and [maui-pr-uitests
1681457](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681457)
were **canceled**, not complete passing runs. Before cancellation, the
four managed-unit Helix jobs completed and all **50 product work-item
XML reports** were audited, excluding controller work items, with no
named failures, assembly errors, or XML/count gaps. In each of
Debug/Release on macOS ARM64/Windows x64, Core recorded **1,125 passed,
0 skipped** and SourceGen **733 passed, 53 existing gated skips**. Those
skips are not passes; configuration counts are not summed into a
unique-test total. This source does not include the separate metadata
correction in #40252. Completed unit XML evidence remains valid despite
cancellation; it does not establish a full build, pack, integration, UI,
or device-test pass.

The human-requested replacement runs use the **same synthetic merge**.
They were initially confirmed **in progress**; the later terminal
UI/device status and remaining main-pipeline coverage are recorded
below:

| Pipeline | Existing replacement run | Queued (UTC) |
| --- | --- | --- |
| `maui-pr` |
[1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489)
| 16:45:42 |
| `maui-pr-uitests` |
[1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
| 16:45:45 |
| `maui-pr-devicetests` |
[1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
| 16:45:48 |

Reuse those runs; no additional pipelines or reviews were queued for
this description update. The native causal chain and original local **77
passed / 0 failed / 0 skipped** result above remain separate evidence,
not replacement-CI results.

The human-requested `maui-copilot` review gate
[16033607](https://dev.azure.com/DevDiv/DevDiv/_build/results?buildId=16033607)
is
**[INCONCLUSIVE](#40258 (comment):
provisioning stopped before verifying/checking out the PR head,
establishing a baseline, or running tests. Its trusted runner source
`e1140933230eabacbaf6412c0b8d80ece38f2d48` is not the tested PR source.
Original Azure raw log 12 contains 32 physical lines; lines 13, 21, and
29 repeat the protection refusal across the three existing setup
attempts: "The new servicing/staging target must have branch protection
before credential-bearing provisioning can run. Refusing to switch."
GitHub independently reports `candidate/11.0.1xx-sr2` as
`protected=false`.

This gate supplied **no test execution or causal-baseline result**. It
is not a test-red verdict or evidence against the sample fix. Deploying
the required candidate branch protection is a **maintainer action**; do
not bypass or modify the guard. Full replacement-CI outcomes and a
successfully provisioned review gate remain outstanding.

**Later CI/review evidence (2026-11-14 UTC)**

[Expert review
5905946810](#40258 (review))
reviewed exact head `026e646e5f820804ca655813a9a5c0e83e40e115` and
reported **zero findings**. Its state is `COMMENTED`, not human approval
or a successful runtime gate. Candidate protection is still `false`; the
provisioning gate described above remains blocked.

In [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
at the same `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` merge, the
**CoreCLR device-test build failed before runtime execution**. Original
raw log 63 records nine CA1416 diagnostics while compiling Essentials
`net11.0-ios27.0`: three deprecated `UIGraphics` calls in
`MediaPicker/ImageProcessor.ios.cs` and six availability calls in
`Passkeys/Passkeys.ios.cs`. The original binlog confirms those nine
diagnostics plus one outer `BuildFailed`, not independent faults in
every downstream project. Three dependent CoreCLR runtime stages were
skipped, leaving a coverage gap.

Those two Essentials source files are byte-identical on the target and
candidate. The actual candidate control [device run
1681310](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681310),
source `77a87edc03aa2728d7e0a51050da0e424a82c801`, completed the CoreCLR
build successfully with zero errors (original raw log 67). This build
failure is unrelated to the sample's one XAML attribute; the precise
analyzer-input divergence remains **unproven**. No speculative
availability/source fix or analyzer suppression is proposed.

Completed portions of [replacement UI run
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490),
on the same merge, supply separate unchanged MacCatalyst evidence:
CollectionView7 run **46901196** recorded **52 passed, 0 skipped**,
including both #31899 header/footer cases, with no retry; mixed drag
shard run **46901170** recorded **57 passed, 1 existing skip**,
including the #12060 and #28416 cases, with no retry. These are not
evidence of a causal MacCatalyst repair by this Android
incremental-sample change.

The MacCatalyst Navigation shard still has **two failures on both the
original attempt and existing retry**: #21814 receives an empty
navigation-event string, and #23902 receives "NavigatedTo called 2
times" instead of 3. Original raw log 3790 and publisher log 3792
correlate to run **46901248** (**85 passed, 2 failed, 1 skipped**);
failure details are
[#21814](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087)
and
[#23902](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086).
These repeat separately observed candidate/branch failures and are not
attributed to the unrelated sample delta.

The replacement Android `Github5623`/original 77-case CollectionView2 CI
result is published and passed on its first attempt, as detailed below.
Overall UI run **1681490** and device run **1681491** have completed
failed; main run **1681489** remains in progress with passing
Build/Pack/Unit stages and incomplete integration coverage. Keep the
original local causal/full-77 evidence distinct from completed CI shard
results, recovered initial failures, and remaining pipeline outcomes. No
new queues, review replies, source changes, or protection changes were
made.

**Completed exact-source Android CI (2026-11-14 UTC)**

The original API30 CollectionView2 suite completed in [maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
at synthetic merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` (PR head
`026e646e5f820804ca655813a9a5c0e83e40e115`, candidate base
`dca0930d7167052b18c0fa25b1995fa416c2bb06`). [Original run
46901428](https://dev.azure.com/dnceng-public/public/_TestManagement/Runs?runId=46901428&_a=runCharts)
recorded **77 passed, 0 failed, 0 skipped on the first attempt**. The
actual [Github5623(Android).CollectionViewInfiniteScroll result
100042](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901428/Results/100042)
passed in **9,353 ms**, without a harness retry.

Original Azure [raw log
4026](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4026)
contains 1,254 physical lines and the successful 77-pass summary, with
no failed case or harness retry. [Publisher log
4028](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4028)
links those exact 77 results to run 46901428. All 77 automated names and
their multiplicities match actual-candidate original run 46895912; the
selector, original oracle, and 15-second scroll deadline were not
reduced or changed. This closes the previously recorded local
ARM64/GA-versus-CI-servicing runtime gap **for this original Android
suite only**; the local causal chain remains independently documented
above.

This is not a whole-pipeline or other-platform clearance. The two
MacCatalyst Navigation failures above remain. A separate MacCatalyst
[#25074
result](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228)
fails `ButtonResizesWhenTitleOrImageChangesAltered.png` with **1.14%
difference on both the original attempt and existing retry**; it is
unrelated to this sample delta, not an Android-oracle failure. The
CoreCLR availability-build failure and skipped-runtime coverage gap in
device run 1681491 remain; that overall device run has completed
**failed**, as has UI run 1681490. Candidate protection is still
`false`, so the runtime review gate remains blocked despite the
exact-head zero-findings expert review. Main run 1681489 has passing
Build/Pack/Unit stages, but its incomplete Integration stage prevents a
whole-main pass. The full terminal UI and measured integration scopes
are detailed below. No new queues, review replies, source changes, or
protection changes were made.

**Terminal UI audit and remaining validation (2026-11-14 UTC)**

[maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
has completed **failed** at exact merge
`b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. All **129 original UI task
raw logs**, their own publishers, and **129 actual final result sets**
were audited. Final published records across platforms/categories are
**14,907 passed, 302 NotExecuted, 3 failed**. These are execution
records, **not unique methods or first-attempt green results**. Nineteen
eventually successful tasks retain **71 original failed records** in
their raw logs; retry recovery does not erase those failures or
establish causal repairs. Every raw failure method name appears in a
corresponding final run, but this is a method-name presence check, not a
claim of fully qualified oracle identity equivalence.

The only three final failures are the MacCatalyst cases already
documented: [#25074's 1.14% altered-button
snapshot](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228),
[#23902's two-versus-three navigation
count](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086),
and [#21814's empty navigation-event
text](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087).
The original Android API30 CollectionView2 suite above remains **77
passed, 0 failed, 0 skipped on its first attempt, with no harness
retry**; the full terminal audit independently preserves its original
log 4026, publisher 4028, and run 46901428. The unrelated Mac failures
do not invalidate that exact Android result.

[maui-pr
1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489),
on the same merge, now has completed passing **Build, Pack, and Helix
Unit Test stages**, but **the whole pipeline is not yet passed**. Only
**20 of 23 original integration tasks** have completed measured
summaries: **311 passed, 10 existing skips, 0 failed** in those
completed tasks. Three tasks remain unmeasured/in progress:
`mac_buildtemplate_previous_tests`, Windows `Build`, and Windows
`Blazor`. Their absent results are not zero failures or passes.

Terminal [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
remains **failed**. Its **31 available product XML reports** contain
**22,318 passed, 2 existing Windows Border failures, 549 existing
skips**, with available per-assembly counts checked and no
assembly-error/count gaps. Skip identities, reasons, and multiplicities
match the candidate; counts span available execution/configuration
records, not unique methods. The nine-CA1416 CoreCLR compile failure and
three skipped dependent runtime stages remain a separate coverage gap:
available XML results do not certify the missing CoreCLR matrix.

The PR head, candidate base, and synthetic merge are unchanged.
Candidate protection remains `false`, the provisioning review gate
remains blocked, and zero-findings expert review is still not human
approval or runtime-gate success. No source changes, pushes, new queues,
review replies, or protection changes were made for this validation
update.

**Exact validation commands and results**

```sh
# Passed: Android-only repository build tasks.
dotnet build ./Microsoft.Maui.BuildTasks.slnf -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:BuildTaskOnlyBuild=true -v:q -nologo

# Passed for original, diagnostic control, fixed, reverted, restored, and immutable-head builds.
dotnet build src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj -c Release -f net11.0-android -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:RuntimeIdentifier=android-arm64 -p:EmbedAssembliesIntoApk=true -v:q -nologo

# Passed: original Android NUnit runner, with private transport only.
dotnet build src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -v:q -nologo

# Same command for each original-oracle phase; $resultdir selected a separate retained phase/attempt directory.
# Results are the actual cases in the phase table above; no automatic test retry was added.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE="$resultdir/appium.log" dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'Name=CollectionViewInfiniteScroll' --logger 'trx;LogFileName=original.trx' --results-directory "$resultdir" -v:q -nologo -- "NUnit.TestOutputXml=$resultdir/nunit"

# Passed: original 77-case selector, after pushing and verifying the exact immutable head.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/appium.log dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'TestCategory=CollectionView2' --logger 'trx;LogFileName=collectionview2.trx' --results-directory /Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2 -v:q -nologo -- NUnit.TestOutputXml=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/nunit

# Passed.
xmllint --noout src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml
# Passed.
git diff --check

# Not completed: bounded/stopped during full-solution loading without output; no formatting pass claimed.
# Only XAML changed; native XAML compilation and XML syntax checks above passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml --verify-no-changes --verbosity quiet
```

Direct source build/install/NUnit commands mirror the existing Cake
UI-test recipe and deliberately avoid the local wrapper's global ADB
restart/recovery behavior in this shared environment. Pre-existing
emulators and their ADB server were preserved.

### 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. -->

Relates to #40116, #39491, and #40227. These references are
intentionally non-closing; this corrects the incremental-loading
sample's scroll-mode contract.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…ection update (#39491)

<!-- 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 Details

When the `ItemsUpdatingScrollMode` is set to `KeepItemsInView,` the
items doesnot scroll to the first item , it maintains the current item

### Root Cause

In the `MauiRecyclerView`, the data change observer is paused for
`KeepItemsInView` in `ItemsUpdatingScrollMode` to maintain the first
position of the item.

### Description of Change

We need to observe the data changes for the `KeepItemsInView` option, as
there may be cases where the item might not remain in view.The issue is
fixed by restarting the data change observer in `MauiRecyclerView`.

### Reference PR : #27153 

### Issues Fixed
Fixes #26810 
Fixes #28006
Fixes #29153
Fixes #29145 

### Tested the behaviour in the following platforms
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

### Output Screenshot
Before Issue Fix | After Issue Fix |
|----------|----------|
|<video width="200" height="200" alt="Before Fix video"
src="https://github.com/user-attachments/assets/8adbd870-9c8f-4ac2-bdf2-93301ef0e073">|<video
width="200" height="200" alt="After Fix video"
src="https://github.com/user-attachments/assets/5edb1a05-2a81-46ba-bb1f-353530b4fbc9">|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…40227)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, branched from
`41458556cf5d13573a632b83f89072f8badfb205`. No rebase, retarget, product
change, or merge is included.

### Description of Change

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

Correct the stale `KeepItemsInView` UI-test contract exposed by #40116.
The [CollectionView
documentation](https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/collectionview/scrolling.md#control-scroll-position-when-new-items-are-added)
and current enum XML documentation specify keeping the **first item in
the list** displayed. #39491 and #39493 intentionally implement that
behavior. The remaining Apple test instead expected the previously
visible middle item; the Android branch only checked that this old item
disappeared.

Use the same positive assertions on Android, iOS and MacCatalyst,
retaining the existing Windows exclusion and CollectionView shard.
Verify the initial middle item is actually displayed, insert once, and
positively assert that `cover1.jpg, 0` is displayed. Scroll away again
and verify the new middle identity (`photo.jpg, 9`), then perform the
remaining 24 insertions and positively assert the first item again. This
preserves 25 total updates and prevents the second check from passing
merely because the first insertion already scrolled to the top.

The existing sample inserts at `(Count / 2) - 1`, **not** at index zero;
the first item's identity remains unchanged. No sample IDs, product
behavior, `KeepScrollOffset`, `KeepLastItemInView`, timeouts, retries,
skips, screenshots, tolerances, or CI configuration are changed.
Upstream searches found the existing product fixes above but no
competing test-contract correction.

**Native validation**

Used the original `ui-tests-samples-coreclr` HostApp from
[maui-pr-uitests
1678816](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1678816),
source `fd2f3ce40199b5c48e31a1814a23919f41f6c3d3`, on an isolated iPhone
11 Pro **CoreSimulator iOS 26.5**. The gallery, data source, template,
Apple scroll helper, and both Apple layout implementations have no
source diff between that CI source and this branch's candidate base.
This does not claim the entire binary tree is identical. HostApp
executable SHA-256:
`895101edc9254a6e235051f77cd2bc8e72d4646477b1ed4b308d8de86392396c`.

| Native oracle on the unchanged CI app | Result |
| --- | --- |
| Original Apple test, 25 insertions, old middle-item expectation |
Failed at final `WaitForElement("Vegetables.jpg, 10")`, reproducing CI
(42 s) |
| Corrected positive first-item test | Passed 3/3 (29 s, 31 s, 29 s) |
| Negative mutation: expect the old middle item after the first
insertion | Failed at that wrong-target oracle (25 s) |
| Restored corrected test after the negative mutation | Passed 2/2;
included in the 3/3 above |

Exact test command for the first corrected run (passed 1/1; repeated
with separate result/log paths for the other runs):

```sh
DEVICE_UDID=05DEC405-3AC9-4F2E-8DBC-8B75A0CF9F4C PLATFORM_VERSION=26.5 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/appium-corrected.log dotnet test artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net11.0/Controls.TestCases.iOS.Tests.dll --filter 'FullyQualifiedName~KeepItemsInView' --logger 'trx;LogFileName=corrected.trx' --results-directory /Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/native-corrected
```

The native HostApp was **not rebuilt** using the locally installed Xcode
27.2 or SDK-check bypasses. Only the platform-neutral net11.0 NUnit
runner was rebuilt using installed .NET SDK 11.0.100. The artifact route
deliberately avoids the local HostApp runner's source rebuild and
shutdown of other sessions' simulators. An initial overly specific
discovery filter selected zero tests; it was corrected to the command
above before collecting these outcomes.

Exact compilation/formatting commands and results:

```sh
# Passed: iOS NUnit runner, final corrected source.
dotnet msbuild src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Android NUnit runner compilation; not an Android native execution.
dotnet msbuild src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Catalyst NUnit runner compilation; not a Catalyst native execution.
dotnet msbuild src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/CollectionViewUITests.CollectionViewItemsUpdatingScrollMode.cs --verify-no-changes --verbosity quiet
# Passed.
git diff --check
```

Native Android and MacCatalyst execution and full-suite CI are not
claimed. No duplicate candidate-wide CI run was queued; candidate-wide
coverage remains coordinated separately.

### 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. -->

Relates to #40116, #39491, and #39493. These references are
intentionally non-closing; this fixes the test contract, not the
underlying product issues.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…ng (#40258)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, based on
`dca0930d7167052b18c0fa25b1995fa416c2bb06`. No merge, retarget, rebase,
or manual CI/review request is included.

### Description of Change

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

Make the `Github5623` incremental-loading sample explicitly use
`KeepScrollOffset`. Its implicit `KeepItemsInView` default now
intentionally scrolls to the first item after an insertion (#39491).
That behavior is correct for that mode, but inappropriate for this
sample's continuous user scrolling through asynchronously appended
pages. #40227's documented first-item contract and the production
implementation remain intact.

The original API30 `Github5623(Android).CollectionViewInfiniteScroll`
oracle reproduced the candidate timeout at
`AppiumTouchActions.ScrollTo:333` / original test line 27. Separate
native diagnostics observed successful page appends `10 -> 20 -> 30 ->
40`, each immediately followed by a native zero-delta callback with the
first cell back at index 0/top 0. These rewinds explain the large
cumulative managed scroll offset despite low visible indexes.
Temporarily removing that native rewind as a **diagnostic control only**
eliminated the resets. The native control and all diagnostic code were
then restored and hash-verified before committing.

The committed change is exactly one XAML attribute. The original NUnit
method, discovery of item `12` by actual user gestures, random 20-319
item heights, `MeasureAllItems`, threshold 25, initial/page size 10,
loading implementation, original 15-second `ScrollTo` deadline, waits,
assertions, retries, categories, and screenshots are unchanged. This is
a sample contract correction, not a production rollback or a weakened
test.

Upstream open/recently merged PR searches covered `Github5623`, infinite
scrolling, `KeepItemsInView`, and `KeepScrollOffset`, together with the
exact sample file history. They identified #39491 and #40227 but no
competing sample repair.

**Native evidence**

Used one task-owned API30 Google APIs ARM64 Nexus 5X emulator, 1080x1920
at 420 dpi, with .NET SDK 11.0.100/runtime 11.0.0, source-built Release
HostApp, embedded assemblies, and the original Android NUnit assembly.
Appium transport alone was adapted locally to private ports
4793/8293/7893 and the owned emulator; that adaptation is not committed.
No physical Apple device or host macOS XCTest automation was used.

| Phase | Actual cases | Result |
| --- | --- | --- |
| Unchanged original sample/oracle | 1 | Failed: exact scrolling-to-12
timeout, 18.233251 s |
| Instrumented native trigger-removal control, not the published fix | 1
| Passed, 7.563766 s; appends retained without rewind |
| Non-instrumented sample-only fix | 3 | Passed: 10.791304 / 8.946879 /
8.947579 s |
| Revert only the sample attribute, restore and rebuild original sources
| 1 | Failed: same scrolling-to-12 timeout, 17.930881 s |
| Restore fix, rebuild immutable
`026e646e5f820804ca655813a9a5c0e83e40e115` | 3 | Passed: 8.922002 /
11.637289 / 10.590518 s |
| Unchanged original `TestCategory=CollectionView2` selector on that
pushed immutable head | 77 | **77 passed, 0 failed, 0 skipped**;
original infinite-scroll case passed in 7.278173 s |

Raw TRX and NUnit XML were checked independently and retained for every
invocation. A separate diagnostic run with the original rewind still
enabled passed in 16.054472 s and is **not** counted as a
non-instrumented baseline pass. Five initial zero-test selector
invocations and one Appium argument-quoting setup failure are retained
separately; none establishes an original-oracle outcome.

Immutable-head APK SHA-256:
`1b3cf5c30f5c001919874e540f52183cf41d346a4b7b2bcfa8ab4b1cd687b9f8`.

**Limits:** the local causal chain proves the sample repair on API30
ARM64/.NET 11 GA, and the completed exact-source API30 CI suite below
now supplies CI-servicing confirmation for the original 77-case Android
suite. Other-platform and whole-pipeline clearance are not claimed. The
supplied newest exact-target CI case was green; this PR does not claim
that the latest target was red or that the unrelated managed-unit
correction caused the failure. Candidate-wide CI remains
parent-coordinated.

**CI validation and remaining limits (2026-11-14 UTC snapshot)**

The live PR remains at head `026e646e5f820804ca655813a9a5c0e83e40e115`,
candidate base `dca0930d7167052b18c0fa25b1995fa416c2bb06`, and synthetic
merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. The human-issued
review, rebase, and pipeline requests on November 14 did not change
those source identities.

The earlier [maui-pr
1681455](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681455)
and [maui-pr-uitests
1681457](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681457)
were **canceled**, not complete passing runs. Before cancellation, the
four managed-unit Helix jobs completed and all **50 product work-item
XML reports** were audited, excluding controller work items, with no
named failures, assembly errors, or XML/count gaps. In each of
Debug/Release on macOS ARM64/Windows x64, Core recorded **1,125 passed,
0 skipped** and SourceGen **733 passed, 53 existing gated skips**. Those
skips are not passes; configuration counts are not summed into a
unique-test total. This source does not include the separate metadata
correction in #40252. Completed unit XML evidence remains valid despite
cancellation; it does not establish a full build, pack, integration, UI,
or device-test pass.

The human-requested replacement runs use the **same synthetic merge**.
They were initially confirmed **in progress**; the later terminal
UI/device status and remaining main-pipeline coverage are recorded
below:

| Pipeline | Existing replacement run | Queued (UTC) |
| --- | --- | --- |
| `maui-pr` |
[1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489)
| 16:45:42 |
| `maui-pr-uitests` |
[1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
| 16:45:45 |
| `maui-pr-devicetests` |
[1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
| 16:45:48 |

Reuse those runs; no additional pipelines or reviews were queued for
this description update. The native causal chain and original local **77
passed / 0 failed / 0 skipped** result above remain separate evidence,
not replacement-CI results.

The human-requested `maui-copilot` review gate
[16033607](https://dev.azure.com/DevDiv/DevDiv/_build/results?buildId=16033607)
is
**[INCONCLUSIVE](#40258 (comment):
provisioning stopped before verifying/checking out the PR head,
establishing a baseline, or running tests. Its trusted runner source
`e1140933230eabacbaf6412c0b8d80ece38f2d48` is not the tested PR source.
Original Azure raw log 12 contains 32 physical lines; lines 13, 21, and
29 repeat the protection refusal across the three existing setup
attempts: "The new servicing/staging target must have branch protection
before credential-bearing provisioning can run. Refusing to switch."
GitHub independently reports `candidate/11.0.1xx-sr2` as
`protected=false`.

This gate supplied **no test execution or causal-baseline result**. It
is not a test-red verdict or evidence against the sample fix. Deploying
the required candidate branch protection is a **maintainer action**; do
not bypass or modify the guard. Full replacement-CI outcomes and a
successfully provisioned review gate remain outstanding.

**Later CI/review evidence (2026-11-14 UTC)**

[Expert review
5905946810](#40258 (review))
reviewed exact head `026e646e5f820804ca655813a9a5c0e83e40e115` and
reported **zero findings**. Its state is `COMMENTED`, not human approval
or a successful runtime gate. Candidate protection is still `false`; the
provisioning gate described above remains blocked.

In [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
at the same `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` merge, the
**CoreCLR device-test build failed before runtime execution**. Original
raw log 63 records nine CA1416 diagnostics while compiling Essentials
`net11.0-ios27.0`: three deprecated `UIGraphics` calls in
`MediaPicker/ImageProcessor.ios.cs` and six availability calls in
`Passkeys/Passkeys.ios.cs`. The original binlog confirms those nine
diagnostics plus one outer `BuildFailed`, not independent faults in
every downstream project. Three dependent CoreCLR runtime stages were
skipped, leaving a coverage gap.

Those two Essentials source files are byte-identical on the target and
candidate. The actual candidate control [device run
1681310](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681310),
source `77a87edc03aa2728d7e0a51050da0e424a82c801`, completed the CoreCLR
build successfully with zero errors (original raw log 67). This build
failure is unrelated to the sample's one XAML attribute; the precise
analyzer-input divergence remains **unproven**. No speculative
availability/source fix or analyzer suppression is proposed.

Completed portions of [replacement UI run
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490),
on the same merge, supply separate unchanged MacCatalyst evidence:
CollectionView7 run **46901196** recorded **52 passed, 0 skipped**,
including both #31899 header/footer cases, with no retry; mixed drag
shard run **46901170** recorded **57 passed, 1 existing skip**,
including the #12060 and #28416 cases, with no retry. These are not
evidence of a causal MacCatalyst repair by this Android
incremental-sample change.

The MacCatalyst Navigation shard still has **two failures on both the
original attempt and existing retry**: #21814 receives an empty
navigation-event string, and #23902 receives "NavigatedTo called 2
times" instead of 3. Original raw log 3790 and publisher log 3792
correlate to run **46901248** (**85 passed, 2 failed, 1 skipped**);
failure details are
[#21814](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087)
and
[#23902](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086).
These repeat separately observed candidate/branch failures and are not
attributed to the unrelated sample delta.

The replacement Android `Github5623`/original 77-case CollectionView2 CI
result is published and passed on its first attempt, as detailed below.
Overall UI run **1681490** and device run **1681491** have completed
failed; main run **1681489** remains in progress with passing
Build/Pack/Unit stages and incomplete integration coverage. Keep the
original local causal/full-77 evidence distinct from completed CI shard
results, recovered initial failures, and remaining pipeline outcomes. No
new queues, review replies, source changes, or protection changes were
made.

**Completed exact-source Android CI (2026-11-14 UTC)**

The original API30 CollectionView2 suite completed in [maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
at synthetic merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` (PR head
`026e646e5f820804ca655813a9a5c0e83e40e115`, candidate base
`dca0930d7167052b18c0fa25b1995fa416c2bb06`). [Original run
46901428](https://dev.azure.com/dnceng-public/public/_TestManagement/Runs?runId=46901428&_a=runCharts)
recorded **77 passed, 0 failed, 0 skipped on the first attempt**. The
actual [Github5623(Android).CollectionViewInfiniteScroll result
100042](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901428/Results/100042)
passed in **9,353 ms**, without a harness retry.

Original Azure [raw log
4026](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4026)
contains 1,254 physical lines and the successful 77-pass summary, with
no failed case or harness retry. [Publisher log
4028](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4028)
links those exact 77 results to run 46901428. All 77 automated names and
their multiplicities match actual-candidate original run 46895912; the
selector, original oracle, and 15-second scroll deadline were not
reduced or changed. This closes the previously recorded local
ARM64/GA-versus-CI-servicing runtime gap **for this original Android
suite only**; the local causal chain remains independently documented
above.

This is not a whole-pipeline or other-platform clearance. The two
MacCatalyst Navigation failures above remain. A separate MacCatalyst
[#25074
result](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228)
fails `ButtonResizesWhenTitleOrImageChangesAltered.png` with **1.14%
difference on both the original attempt and existing retry**; it is
unrelated to this sample delta, not an Android-oracle failure. The
CoreCLR availability-build failure and skipped-runtime coverage gap in
device run 1681491 remain; that overall device run has completed
**failed**, as has UI run 1681490. Candidate protection is still
`false`, so the runtime review gate remains blocked despite the
exact-head zero-findings expert review. Main run 1681489 has passing
Build/Pack/Unit stages, but its incomplete Integration stage prevents a
whole-main pass. The full terminal UI and measured integration scopes
are detailed below. No new queues, review replies, source changes, or
protection changes were made.

**Terminal UI audit and remaining validation (2026-11-14 UTC)**

[maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
has completed **failed** at exact merge
`b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. All **129 original UI task
raw logs**, their own publishers, and **129 actual final result sets**
were audited. Final published records across platforms/categories are
**14,907 passed, 302 NotExecuted, 3 failed**. These are execution
records, **not unique methods or first-attempt green results**. Nineteen
eventually successful tasks retain **71 original failed records** in
their raw logs; retry recovery does not erase those failures or
establish causal repairs. Every raw failure method name appears in a
corresponding final run, but this is a method-name presence check, not a
claim of fully qualified oracle identity equivalence.

The only three final failures are the MacCatalyst cases already
documented: [#25074's 1.14% altered-button
snapshot](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228),
[#23902's two-versus-three navigation
count](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086),
and [#21814's empty navigation-event
text](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087).
The original Android API30 CollectionView2 suite above remains **77
passed, 0 failed, 0 skipped on its first attempt, with no harness
retry**; the full terminal audit independently preserves its original
log 4026, publisher 4028, and run 46901428. The unrelated Mac failures
do not invalidate that exact Android result.

[maui-pr
1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489),
on the same merge, now has completed passing **Build, Pack, and Helix
Unit Test stages**, but **the whole pipeline is not yet passed**. Only
**20 of 23 original integration tasks** have completed measured
summaries: **311 passed, 10 existing skips, 0 failed** in those
completed tasks. Three tasks remain unmeasured/in progress:
`mac_buildtemplate_previous_tests`, Windows `Build`, and Windows
`Blazor`. Their absent results are not zero failures or passes.

Terminal [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
remains **failed**. Its **31 available product XML reports** contain
**22,318 passed, 2 existing Windows Border failures, 549 existing
skips**, with available per-assembly counts checked and no
assembly-error/count gaps. Skip identities, reasons, and multiplicities
match the candidate; counts span available execution/configuration
records, not unique methods. The nine-CA1416 CoreCLR compile failure and
three skipped dependent runtime stages remain a separate coverage gap:
available XML results do not certify the missing CoreCLR matrix.

The PR head, candidate base, and synthetic merge are unchanged.
Candidate protection remains `false`, the provisioning review gate
remains blocked, and zero-findings expert review is still not human
approval or runtime-gate success. No source changes, pushes, new queues,
review replies, or protection changes were made for this validation
update.

**Exact validation commands and results**

```sh
# Passed: Android-only repository build tasks.
dotnet build ./Microsoft.Maui.BuildTasks.slnf -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:BuildTaskOnlyBuild=true -v:q -nologo

# Passed for original, diagnostic control, fixed, reverted, restored, and immutable-head builds.
dotnet build src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj -c Release -f net11.0-android -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:RuntimeIdentifier=android-arm64 -p:EmbedAssembliesIntoApk=true -v:q -nologo

# Passed: original Android NUnit runner, with private transport only.
dotnet build src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -v:q -nologo

# Same command for each original-oracle phase; $resultdir selected a separate retained phase/attempt directory.
# Results are the actual cases in the phase table above; no automatic test retry was added.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE="$resultdir/appium.log" dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'Name=CollectionViewInfiniteScroll' --logger 'trx;LogFileName=original.trx' --results-directory "$resultdir" -v:q -nologo -- "NUnit.TestOutputXml=$resultdir/nunit"

# Passed: original 77-case selector, after pushing and verifying the exact immutable head.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/appium.log dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'TestCategory=CollectionView2' --logger 'trx;LogFileName=collectionview2.trx' --results-directory /Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2 -v:q -nologo -- NUnit.TestOutputXml=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/nunit

# Passed.
xmllint --noout src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml
# Passed.
git diff --check

# Not completed: bounded/stopped during full-solution loading without output; no formatting pass claimed.
# Only XAML changed; native XAML compilation and XML syntax checks above passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml --verify-no-changes --verbosity quiet
```

Direct source build/install/NUnit commands mirror the existing Cake
UI-test recipe and deliberately avoid the local wrapper's global ADB
restart/recovery behavior in this shared environment. Pre-existing
emulators and their ADB server were preserved.

### 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. -->

Relates to #40116, #39491, and #40227. These references are
intentionally non-closing; this corrects the incremental-loading
sample's scroll-mode contract.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…ection update (#39491)

<!-- 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 Details

When the `ItemsUpdatingScrollMode` is set to `KeepItemsInView,` the
items doesnot scroll to the first item , it maintains the current item

### Root Cause

In the `MauiRecyclerView`, the data change observer is paused for
`KeepItemsInView` in `ItemsUpdatingScrollMode` to maintain the first
position of the item.

### Description of Change

We need to observe the data changes for the `KeepItemsInView` option, as
there may be cases where the item might not remain in view.The issue is
fixed by restarting the data change observer in `MauiRecyclerView`.

### Reference PR : #27153 

### Issues Fixed
Fixes #26810 
Fixes #28006
Fixes #29153
Fixes #29145 

### Tested the behaviour in the following platforms
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

### Output Screenshot
Before Issue Fix | After Issue Fix |
|----------|----------|
|<video width="200" height="200" alt="Before Fix video"
src="https://github.com/user-attachments/assets/8adbd870-9c8f-4ac2-bdf2-93301ef0e073">|<video
width="200" height="200" alt="After Fix video"
src="https://github.com/user-attachments/assets/5edb1a05-2a81-46ba-bb1f-353530b4fbc9">|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…40227)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, branched from
`41458556cf5d13573a632b83f89072f8badfb205`. No rebase, retarget, product
change, or merge is included.

### Description of Change

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

Correct the stale `KeepItemsInView` UI-test contract exposed by #40116.
The [CollectionView
documentation](https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/collectionview/scrolling.md#control-scroll-position-when-new-items-are-added)
and current enum XML documentation specify keeping the **first item in
the list** displayed. #39491 and #39493 intentionally implement that
behavior. The remaining Apple test instead expected the previously
visible middle item; the Android branch only checked that this old item
disappeared.

Use the same positive assertions on Android, iOS and MacCatalyst,
retaining the existing Windows exclusion and CollectionView shard.
Verify the initial middle item is actually displayed, insert once, and
positively assert that `cover1.jpg, 0` is displayed. Scroll away again
and verify the new middle identity (`photo.jpg, 9`), then perform the
remaining 24 insertions and positively assert the first item again. This
preserves 25 total updates and prevents the second check from passing
merely because the first insertion already scrolled to the top.

The existing sample inserts at `(Count / 2) - 1`, **not** at index zero;
the first item's identity remains unchanged. No sample IDs, product
behavior, `KeepScrollOffset`, `KeepLastItemInView`, timeouts, retries,
skips, screenshots, tolerances, or CI configuration are changed.
Upstream searches found the existing product fixes above but no
competing test-contract correction.

**Native validation**

Used the original `ui-tests-samples-coreclr` HostApp from
[maui-pr-uitests
1678816](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1678816),
source `fd2f3ce40199b5c48e31a1814a23919f41f6c3d3`, on an isolated iPhone
11 Pro **CoreSimulator iOS 26.5**. The gallery, data source, template,
Apple scroll helper, and both Apple layout implementations have no
source diff between that CI source and this branch's candidate base.
This does not claim the entire binary tree is identical. HostApp
executable SHA-256:
`895101edc9254a6e235051f77cd2bc8e72d4646477b1ed4b308d8de86392396c`.

| Native oracle on the unchanged CI app | Result |
| --- | --- |
| Original Apple test, 25 insertions, old middle-item expectation |
Failed at final `WaitForElement("Vegetables.jpg, 10")`, reproducing CI
(42 s) |
| Corrected positive first-item test | Passed 3/3 (29 s, 31 s, 29 s) |
| Negative mutation: expect the old middle item after the first
insertion | Failed at that wrong-target oracle (25 s) |
| Restored corrected test after the negative mutation | Passed 2/2;
included in the 3/3 above |

Exact test command for the first corrected run (passed 1/1; repeated
with separate result/log paths for the other runs):

```sh
DEVICE_UDID=05DEC405-3AC9-4F2E-8DBC-8B75A0CF9F4C PLATFORM_VERSION=26.5 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/appium-corrected.log dotnet test artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net11.0/Controls.TestCases.iOS.Tests.dll --filter 'FullyQualifiedName~KeepItemsInView' --logger 'trx;LogFileName=corrected.trx' --results-directory /Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/native-corrected
```

The native HostApp was **not rebuilt** using the locally installed Xcode
27.2 or SDK-check bypasses. Only the platform-neutral net11.0 NUnit
runner was rebuilt using installed .NET SDK 11.0.100. The artifact route
deliberately avoids the local HostApp runner's source rebuild and
shutdown of other sessions' simulators. An initial overly specific
discovery filter selected zero tests; it was corrected to the command
above before collecting these outcomes.

Exact compilation/formatting commands and results:

```sh
# Passed: iOS NUnit runner, final corrected source.
dotnet msbuild src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Android NUnit runner compilation; not an Android native execution.
dotnet msbuild src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Catalyst NUnit runner compilation; not a Catalyst native execution.
dotnet msbuild src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/CollectionViewUITests.CollectionViewItemsUpdatingScrollMode.cs --verify-no-changes --verbosity quiet
# Passed.
git diff --check
```

Native Android and MacCatalyst execution and full-suite CI are not
claimed. No duplicate candidate-wide CI run was queued; candidate-wide
coverage remains coordinated separately.

### 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. -->

Relates to #40116, #39491, and #39493. These references are
intentionally non-closing; this fixes the test contract, not the
underlying product issues.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 18, 2026
…ng (#40258)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, based on
`dca0930d7167052b18c0fa25b1995fa416c2bb06`. No merge, retarget, rebase,
or manual CI/review request is included.

### Description of Change

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

Make the `Github5623` incremental-loading sample explicitly use
`KeepScrollOffset`. Its implicit `KeepItemsInView` default now
intentionally scrolls to the first item after an insertion (#39491).
That behavior is correct for that mode, but inappropriate for this
sample's continuous user scrolling through asynchronously appended
pages. #40227's documented first-item contract and the production
implementation remain intact.

The original API30 `Github5623(Android).CollectionViewInfiniteScroll`
oracle reproduced the candidate timeout at
`AppiumTouchActions.ScrollTo:333` / original test line 27. Separate
native diagnostics observed successful page appends `10 -> 20 -> 30 ->
40`, each immediately followed by a native zero-delta callback with the
first cell back at index 0/top 0. These rewinds explain the large
cumulative managed scroll offset despite low visible indexes.
Temporarily removing that native rewind as a **diagnostic control only**
eliminated the resets. The native control and all diagnostic code were
then restored and hash-verified before committing.

The committed change is exactly one XAML attribute. The original NUnit
method, discovery of item `12` by actual user gestures, random 20-319
item heights, `MeasureAllItems`, threshold 25, initial/page size 10,
loading implementation, original 15-second `ScrollTo` deadline, waits,
assertions, retries, categories, and screenshots are unchanged. This is
a sample contract correction, not a production rollback or a weakened
test.

Upstream open/recently merged PR searches covered `Github5623`, infinite
scrolling, `KeepItemsInView`, and `KeepScrollOffset`, together with the
exact sample file history. They identified #39491 and #40227 but no
competing sample repair.

**Native evidence**

Used one task-owned API30 Google APIs ARM64 Nexus 5X emulator, 1080x1920
at 420 dpi, with .NET SDK 11.0.100/runtime 11.0.0, source-built Release
HostApp, embedded assemblies, and the original Android NUnit assembly.
Appium transport alone was adapted locally to private ports
4793/8293/7893 and the owned emulator; that adaptation is not committed.
No physical Apple device or host macOS XCTest automation was used.

| Phase | Actual cases | Result |
| --- | --- | --- |
| Unchanged original sample/oracle | 1 | Failed: exact scrolling-to-12
timeout, 18.233251 s |
| Instrumented native trigger-removal control, not the published fix | 1
| Passed, 7.563766 s; appends retained without rewind |
| Non-instrumented sample-only fix | 3 | Passed: 10.791304 / 8.946879 /
8.947579 s |
| Revert only the sample attribute, restore and rebuild original sources
| 1 | Failed: same scrolling-to-12 timeout, 17.930881 s |
| Restore fix, rebuild immutable
`026e646e5f820804ca655813a9a5c0e83e40e115` | 3 | Passed: 8.922002 /
11.637289 / 10.590518 s |
| Unchanged original `TestCategory=CollectionView2` selector on that
pushed immutable head | 77 | **77 passed, 0 failed, 0 skipped**;
original infinite-scroll case passed in 7.278173 s |

Raw TRX and NUnit XML were checked independently and retained for every
invocation. A separate diagnostic run with the original rewind still
enabled passed in 16.054472 s and is **not** counted as a
non-instrumented baseline pass. Five initial zero-test selector
invocations and one Appium argument-quoting setup failure are retained
separately; none establishes an original-oracle outcome.

Immutable-head APK SHA-256:
`1b3cf5c30f5c001919874e540f52183cf41d346a4b7b2bcfa8ab4b1cd687b9f8`.

**Limits:** the local causal chain proves the sample repair on API30
ARM64/.NET 11 GA, and the completed exact-source API30 CI suite below
now supplies CI-servicing confirmation for the original 77-case Android
suite. Other-platform and whole-pipeline clearance are not claimed. The
supplied newest exact-target CI case was green; this PR does not claim
that the latest target was red or that the unrelated managed-unit
correction caused the failure. Candidate-wide CI remains
parent-coordinated.

**CI validation and remaining limits (2026-11-14 UTC snapshot)**

The live PR remains at head `026e646e5f820804ca655813a9a5c0e83e40e115`,
candidate base `dca0930d7167052b18c0fa25b1995fa416c2bb06`, and synthetic
merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. The human-issued
review, rebase, and pipeline requests on November 14 did not change
those source identities.

The earlier [maui-pr
1681455](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681455)
and [maui-pr-uitests
1681457](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681457)
were **canceled**, not complete passing runs. Before cancellation, the
four managed-unit Helix jobs completed and all **50 product work-item
XML reports** were audited, excluding controller work items, with no
named failures, assembly errors, or XML/count gaps. In each of
Debug/Release on macOS ARM64/Windows x64, Core recorded **1,125 passed,
0 skipped** and SourceGen **733 passed, 53 existing gated skips**. Those
skips are not passes; configuration counts are not summed into a
unique-test total. This source does not include the separate metadata
correction in #40252. Completed unit XML evidence remains valid despite
cancellation; it does not establish a full build, pack, integration, UI,
or device-test pass.

The human-requested replacement runs use the **same synthetic merge**.
They were initially confirmed **in progress**; the later terminal
UI/device status and remaining main-pipeline coverage are recorded
below:

| Pipeline | Existing replacement run | Queued (UTC) |
| --- | --- | --- |
| `maui-pr` |
[1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489)
| 16:45:42 |
| `maui-pr-uitests` |
[1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
| 16:45:45 |
| `maui-pr-devicetests` |
[1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
| 16:45:48 |

Reuse those runs; no additional pipelines or reviews were queued for
this description update. The native causal chain and original local **77
passed / 0 failed / 0 skipped** result above remain separate evidence,
not replacement-CI results.

The human-requested `maui-copilot` review gate
[16033607](https://dev.azure.com/DevDiv/DevDiv/_build/results?buildId=16033607)
is
**[INCONCLUSIVE](#40258 (comment):
provisioning stopped before verifying/checking out the PR head,
establishing a baseline, or running tests. Its trusted runner source
`e1140933230eabacbaf6412c0b8d80ece38f2d48` is not the tested PR source.
Original Azure raw log 12 contains 32 physical lines; lines 13, 21, and
29 repeat the protection refusal across the three existing setup
attempts: "The new servicing/staging target must have branch protection
before credential-bearing provisioning can run. Refusing to switch."
GitHub independently reports `candidate/11.0.1xx-sr2` as
`protected=false`.

This gate supplied **no test execution or causal-baseline result**. It
is not a test-red verdict or evidence against the sample fix. Deploying
the required candidate branch protection is a **maintainer action**; do
not bypass or modify the guard. Full replacement-CI outcomes and a
successfully provisioned review gate remain outstanding.

**Later CI/review evidence (2026-11-14 UTC)**

[Expert review
5905946810](#40258 (review))
reviewed exact head `026e646e5f820804ca655813a9a5c0e83e40e115` and
reported **zero findings**. Its state is `COMMENTED`, not human approval
or a successful runtime gate. Candidate protection is still `false`; the
provisioning gate described above remains blocked.

In [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
at the same `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` merge, the
**CoreCLR device-test build failed before runtime execution**. Original
raw log 63 records nine CA1416 diagnostics while compiling Essentials
`net11.0-ios27.0`: three deprecated `UIGraphics` calls in
`MediaPicker/ImageProcessor.ios.cs` and six availability calls in
`Passkeys/Passkeys.ios.cs`. The original binlog confirms those nine
diagnostics plus one outer `BuildFailed`, not independent faults in
every downstream project. Three dependent CoreCLR runtime stages were
skipped, leaving a coverage gap.

Those two Essentials source files are byte-identical on the target and
candidate. The actual candidate control [device run
1681310](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681310),
source `77a87edc03aa2728d7e0a51050da0e424a82c801`, completed the CoreCLR
build successfully with zero errors (original raw log 67). This build
failure is unrelated to the sample's one XAML attribute; the precise
analyzer-input divergence remains **unproven**. No speculative
availability/source fix or analyzer suppression is proposed.

Completed portions of [replacement UI run
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490),
on the same merge, supply separate unchanged MacCatalyst evidence:
CollectionView7 run **46901196** recorded **52 passed, 0 skipped**,
including both #31899 header/footer cases, with no retry; mixed drag
shard run **46901170** recorded **57 passed, 1 existing skip**,
including the #12060 and #28416 cases, with no retry. These are not
evidence of a causal MacCatalyst repair by this Android
incremental-sample change.

The MacCatalyst Navigation shard still has **two failures on both the
original attempt and existing retry**: #21814 receives an empty
navigation-event string, and #23902 receives "NavigatedTo called 2
times" instead of 3. Original raw log 3790 and publisher log 3792
correlate to run **46901248** (**85 passed, 2 failed, 1 skipped**);
failure details are
[#21814](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087)
and
[#23902](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086).
These repeat separately observed candidate/branch failures and are not
attributed to the unrelated sample delta.

The replacement Android `Github5623`/original 77-case CollectionView2 CI
result is published and passed on its first attempt, as detailed below.
Overall UI run **1681490** and device run **1681491** have completed
failed; main run **1681489** remains in progress with passing
Build/Pack/Unit stages and incomplete integration coverage. Keep the
original local causal/full-77 evidence distinct from completed CI shard
results, recovered initial failures, and remaining pipeline outcomes. No
new queues, review replies, source changes, or protection changes were
made.

**Completed exact-source Android CI (2026-11-14 UTC)**

The original API30 CollectionView2 suite completed in [maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
at synthetic merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` (PR head
`026e646e5f820804ca655813a9a5c0e83e40e115`, candidate base
`dca0930d7167052b18c0fa25b1995fa416c2bb06`). [Original run
46901428](https://dev.azure.com/dnceng-public/public/_TestManagement/Runs?runId=46901428&_a=runCharts)
recorded **77 passed, 0 failed, 0 skipped on the first attempt**. The
actual [Github5623(Android).CollectionViewInfiniteScroll result
100042](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901428/Results/100042)
passed in **9,353 ms**, without a harness retry.

Original Azure [raw log
4026](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4026)
contains 1,254 physical lines and the successful 77-pass summary, with
no failed case or harness retry. [Publisher log
4028](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4028)
links those exact 77 results to run 46901428. All 77 automated names and
their multiplicities match actual-candidate original run 46895912; the
selector, original oracle, and 15-second scroll deadline were not
reduced or changed. This closes the previously recorded local
ARM64/GA-versus-CI-servicing runtime gap **for this original Android
suite only**; the local causal chain remains independently documented
above.

This is not a whole-pipeline or other-platform clearance. The two
MacCatalyst Navigation failures above remain. A separate MacCatalyst
[#25074
result](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228)
fails `ButtonResizesWhenTitleOrImageChangesAltered.png` with **1.14%
difference on both the original attempt and existing retry**; it is
unrelated to this sample delta, not an Android-oracle failure. The
CoreCLR availability-build failure and skipped-runtime coverage gap in
device run 1681491 remain; that overall device run has completed
**failed**, as has UI run 1681490. Candidate protection is still
`false`, so the runtime review gate remains blocked despite the
exact-head zero-findings expert review. Main run 1681489 has passing
Build/Pack/Unit stages, but its incomplete Integration stage prevents a
whole-main pass. The full terminal UI and measured integration scopes
are detailed below. No new queues, review replies, source changes, or
protection changes were made.

**Terminal UI audit and remaining validation (2026-11-14 UTC)**

[maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
has completed **failed** at exact merge
`b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. All **129 original UI task
raw logs**, their own publishers, and **129 actual final result sets**
were audited. Final published records across platforms/categories are
**14,907 passed, 302 NotExecuted, 3 failed**. These are execution
records, **not unique methods or first-attempt green results**. Nineteen
eventually successful tasks retain **71 original failed records** in
their raw logs; retry recovery does not erase those failures or
establish causal repairs. Every raw failure method name appears in a
corresponding final run, but this is a method-name presence check, not a
claim of fully qualified oracle identity equivalence.

The only three final failures are the MacCatalyst cases already
documented: [#25074's 1.14% altered-button
snapshot](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228),
[#23902's two-versus-three navigation
count](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086),
and [#21814's empty navigation-event
text](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087).
The original Android API30 CollectionView2 suite above remains **77
passed, 0 failed, 0 skipped on its first attempt, with no harness
retry**; the full terminal audit independently preserves its original
log 4026, publisher 4028, and run 46901428. The unrelated Mac failures
do not invalidate that exact Android result.

[maui-pr
1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489),
on the same merge, now has completed passing **Build, Pack, and Helix
Unit Test stages**, but **the whole pipeline is not yet passed**. Only
**20 of 23 original integration tasks** have completed measured
summaries: **311 passed, 10 existing skips, 0 failed** in those
completed tasks. Three tasks remain unmeasured/in progress:
`mac_buildtemplate_previous_tests`, Windows `Build`, and Windows
`Blazor`. Their absent results are not zero failures or passes.

Terminal [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
remains **failed**. Its **31 available product XML reports** contain
**22,318 passed, 2 existing Windows Border failures, 549 existing
skips**, with available per-assembly counts checked and no
assembly-error/count gaps. Skip identities, reasons, and multiplicities
match the candidate; counts span available execution/configuration
records, not unique methods. The nine-CA1416 CoreCLR compile failure and
three skipped dependent runtime stages remain a separate coverage gap:
available XML results do not certify the missing CoreCLR matrix.

The PR head, candidate base, and synthetic merge are unchanged.
Candidate protection remains `false`, the provisioning review gate
remains blocked, and zero-findings expert review is still not human
approval or runtime-gate success. No source changes, pushes, new queues,
review replies, or protection changes were made for this validation
update.

**Exact validation commands and results**

```sh
# Passed: Android-only repository build tasks.
dotnet build ./Microsoft.Maui.BuildTasks.slnf -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:BuildTaskOnlyBuild=true -v:q -nologo

# Passed for original, diagnostic control, fixed, reverted, restored, and immutable-head builds.
dotnet build src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj -c Release -f net11.0-android -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:RuntimeIdentifier=android-arm64 -p:EmbedAssembliesIntoApk=true -v:q -nologo

# Passed: original Android NUnit runner, with private transport only.
dotnet build src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -v:q -nologo

# Same command for each original-oracle phase; $resultdir selected a separate retained phase/attempt directory.
# Results are the actual cases in the phase table above; no automatic test retry was added.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE="$resultdir/appium.log" dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'Name=CollectionViewInfiniteScroll' --logger 'trx;LogFileName=original.trx' --results-directory "$resultdir" -v:q -nologo -- "NUnit.TestOutputXml=$resultdir/nunit"

# Passed: original 77-case selector, after pushing and verifying the exact immutable head.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/appium.log dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'TestCategory=CollectionView2' --logger 'trx;LogFileName=collectionview2.trx' --results-directory /Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2 -v:q -nologo -- NUnit.TestOutputXml=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/nunit

# Passed.
xmllint --noout src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml
# Passed.
git diff --check

# Not completed: bounded/stopped during full-solution loading without output; no formatting pass claimed.
# Only XAML changed; native XAML compilation and XML syntax checks above passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml --verify-no-changes --verbosity quiet
```

Direct source build/install/NUnit commands mirror the existing Cake
UI-test recipe and deliberately avoid the local wrapper's global ADB
restart/recovery behavior in this shared environment. Pre-existing
emulators and their ADB server were preserved.

### 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. -->

Relates to #40116, #39491, and #40227. These references are
intentionally non-closing; this corrects the incremental-loading
sample's scroll-mode contract.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 19, 2026
…ection update (#39491)

<!-- 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 Details

When the `ItemsUpdatingScrollMode` is set to `KeepItemsInView,` the
items doesnot scroll to the first item , it maintains the current item

### Root Cause

In the `MauiRecyclerView`, the data change observer is paused for
`KeepItemsInView` in `ItemsUpdatingScrollMode` to maintain the first
position of the item.

### Description of Change

We need to observe the data changes for the `KeepItemsInView` option, as
there may be cases where the item might not remain in view.The issue is
fixed by restarting the data change observer in `MauiRecyclerView`.

### Reference PR : #27153 

### Issues Fixed
Fixes #26810 
Fixes #28006
Fixes #29153
Fixes #29145 

### Tested the behaviour in the following platforms
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

### Output Screenshot
Before Issue Fix | After Issue Fix |
|----------|----------|
|<video width="200" height="200" alt="Before Fix video"
src="https://github.com/user-attachments/assets/8adbd870-9c8f-4ac2-bdf2-93301ef0e073">|<video
width="200" height="200" alt="After Fix video"
src="https://github.com/user-attachments/assets/5edb1a05-2a81-46ba-bb1f-353530b4fbc9">|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 19, 2026
…40227)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, branched from
`41458556cf5d13573a632b83f89072f8badfb205`. No rebase, retarget, product
change, or merge is included.

### Description of Change

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

Correct the stale `KeepItemsInView` UI-test contract exposed by #40116.
The [CollectionView
documentation](https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/collectionview/scrolling.md#control-scroll-position-when-new-items-are-added)
and current enum XML documentation specify keeping the **first item in
the list** displayed. #39491 and #39493 intentionally implement that
behavior. The remaining Apple test instead expected the previously
visible middle item; the Android branch only checked that this old item
disappeared.

Use the same positive assertions on Android, iOS and MacCatalyst,
retaining the existing Windows exclusion and CollectionView shard.
Verify the initial middle item is actually displayed, insert once, and
positively assert that `cover1.jpg, 0` is displayed. Scroll away again
and verify the new middle identity (`photo.jpg, 9`), then perform the
remaining 24 insertions and positively assert the first item again. This
preserves 25 total updates and prevents the second check from passing
merely because the first insertion already scrolled to the top.

The existing sample inserts at `(Count / 2) - 1`, **not** at index zero;
the first item's identity remains unchanged. No sample IDs, product
behavior, `KeepScrollOffset`, `KeepLastItemInView`, timeouts, retries,
skips, screenshots, tolerances, or CI configuration are changed.
Upstream searches found the existing product fixes above but no
competing test-contract correction.

**Native validation**

Used the original `ui-tests-samples-coreclr` HostApp from
[maui-pr-uitests
1678816](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1678816),
source `fd2f3ce40199b5c48e31a1814a23919f41f6c3d3`, on an isolated iPhone
11 Pro **CoreSimulator iOS 26.5**. The gallery, data source, template,
Apple scroll helper, and both Apple layout implementations have no
source diff between that CI source and this branch's candidate base.
This does not claim the entire binary tree is identical. HostApp
executable SHA-256:
`895101edc9254a6e235051f77cd2bc8e72d4646477b1ed4b308d8de86392396c`.

| Native oracle on the unchanged CI app | Result |
| --- | --- |
| Original Apple test, 25 insertions, old middle-item expectation |
Failed at final `WaitForElement("Vegetables.jpg, 10")`, reproducing CI
(42 s) |
| Corrected positive first-item test | Passed 3/3 (29 s, 31 s, 29 s) |
| Negative mutation: expect the old middle item after the first
insertion | Failed at that wrong-target oracle (25 s) |
| Restored corrected test after the negative mutation | Passed 2/2;
included in the 3/3 above |

Exact test command for the first corrected run (passed 1/1; repeated
with separate result/log paths for the other runs):

```sh
DEVICE_UDID=05DEC405-3AC9-4F2E-8DBC-8B75A0CF9F4C PLATFORM_VERSION=26.5 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/appium-corrected.log dotnet test artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net11.0/Controls.TestCases.iOS.Tests.dll --filter 'FullyQualifiedName~KeepItemsInView' --logger 'trx;LogFileName=corrected.trx' --results-directory /Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/native-corrected
```

The native HostApp was **not rebuilt** using the locally installed Xcode
27.2 or SDK-check bypasses. Only the platform-neutral net11.0 NUnit
runner was rebuilt using installed .NET SDK 11.0.100. The artifact route
deliberately avoids the local HostApp runner's source rebuild and
shutdown of other sessions' simulators. An initial overly specific
discovery filter selected zero tests; it was corrected to the command
above before collecting these outcomes.

Exact compilation/formatting commands and results:

```sh
# Passed: iOS NUnit runner, final corrected source.
dotnet msbuild src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Android NUnit runner compilation; not an Android native execution.
dotnet msbuild src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Catalyst NUnit runner compilation; not a Catalyst native execution.
dotnet msbuild src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/CollectionViewUITests.CollectionViewItemsUpdatingScrollMode.cs --verify-no-changes --verbosity quiet
# Passed.
git diff --check
```

Native Android and MacCatalyst execution and full-suite CI are not
claimed. No duplicate candidate-wide CI run was queued; candidate-wide
coverage remains coordinated separately.

### 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. -->

Relates to #40116, #39491, and #39493. These references are
intentionally non-closing; this fixes the test contract, not the
underlying product issues.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 19, 2026
…ng (#40258)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, based on
`dca0930d7167052b18c0fa25b1995fa416c2bb06`. No merge, retarget, rebase,
or manual CI/review request is included.

### Description of Change

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

Make the `Github5623` incremental-loading sample explicitly use
`KeepScrollOffset`. Its implicit `KeepItemsInView` default now
intentionally scrolls to the first item after an insertion (#39491).
That behavior is correct for that mode, but inappropriate for this
sample's continuous user scrolling through asynchronously appended
pages. #40227's documented first-item contract and the production
implementation remain intact.

The original API30 `Github5623(Android).CollectionViewInfiniteScroll`
oracle reproduced the candidate timeout at
`AppiumTouchActions.ScrollTo:333` / original test line 27. Separate
native diagnostics observed successful page appends `10 -> 20 -> 30 ->
40`, each immediately followed by a native zero-delta callback with the
first cell back at index 0/top 0. These rewinds explain the large
cumulative managed scroll offset despite low visible indexes.
Temporarily removing that native rewind as a **diagnostic control only**
eliminated the resets. The native control and all diagnostic code were
then restored and hash-verified before committing.

The committed change is exactly one XAML attribute. The original NUnit
method, discovery of item `12` by actual user gestures, random 20-319
item heights, `MeasureAllItems`, threshold 25, initial/page size 10,
loading implementation, original 15-second `ScrollTo` deadline, waits,
assertions, retries, categories, and screenshots are unchanged. This is
a sample contract correction, not a production rollback or a weakened
test.

Upstream open/recently merged PR searches covered `Github5623`, infinite
scrolling, `KeepItemsInView`, and `KeepScrollOffset`, together with the
exact sample file history. They identified #39491 and #40227 but no
competing sample repair.

**Native evidence**

Used one task-owned API30 Google APIs ARM64 Nexus 5X emulator, 1080x1920
at 420 dpi, with .NET SDK 11.0.100/runtime 11.0.0, source-built Release
HostApp, embedded assemblies, and the original Android NUnit assembly.
Appium transport alone was adapted locally to private ports
4793/8293/7893 and the owned emulator; that adaptation is not committed.
No physical Apple device or host macOS XCTest automation was used.

| Phase | Actual cases | Result |
| --- | --- | --- |
| Unchanged original sample/oracle | 1 | Failed: exact scrolling-to-12
timeout, 18.233251 s |
| Instrumented native trigger-removal control, not the published fix | 1
| Passed, 7.563766 s; appends retained without rewind |
| Non-instrumented sample-only fix | 3 | Passed: 10.791304 / 8.946879 /
8.947579 s |
| Revert only the sample attribute, restore and rebuild original sources
| 1 | Failed: same scrolling-to-12 timeout, 17.930881 s |
| Restore fix, rebuild immutable
`026e646e5f820804ca655813a9a5c0e83e40e115` | 3 | Passed: 8.922002 /
11.637289 / 10.590518 s |
| Unchanged original `TestCategory=CollectionView2` selector on that
pushed immutable head | 77 | **77 passed, 0 failed, 0 skipped**;
original infinite-scroll case passed in 7.278173 s |

Raw TRX and NUnit XML were checked independently and retained for every
invocation. A separate diagnostic run with the original rewind still
enabled passed in 16.054472 s and is **not** counted as a
non-instrumented baseline pass. Five initial zero-test selector
invocations and one Appium argument-quoting setup failure are retained
separately; none establishes an original-oracle outcome.

Immutable-head APK SHA-256:
`1b3cf5c30f5c001919874e540f52183cf41d346a4b7b2bcfa8ab4b1cd687b9f8`.

**Limits:** the local causal chain proves the sample repair on API30
ARM64/.NET 11 GA, and the completed exact-source API30 CI suite below
now supplies CI-servicing confirmation for the original 77-case Android
suite. Other-platform and whole-pipeline clearance are not claimed. The
supplied newest exact-target CI case was green; this PR does not claim
that the latest target was red or that the unrelated managed-unit
correction caused the failure. Candidate-wide CI remains
parent-coordinated.

**CI validation and remaining limits (2026-11-14 UTC snapshot)**

The live PR remains at head `026e646e5f820804ca655813a9a5c0e83e40e115`,
candidate base `dca0930d7167052b18c0fa25b1995fa416c2bb06`, and synthetic
merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. The human-issued
review, rebase, and pipeline requests on November 14 did not change
those source identities.

The earlier [maui-pr
1681455](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681455)
and [maui-pr-uitests
1681457](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681457)
were **canceled**, not complete passing runs. Before cancellation, the
four managed-unit Helix jobs completed and all **50 product work-item
XML reports** were audited, excluding controller work items, with no
named failures, assembly errors, or XML/count gaps. In each of
Debug/Release on macOS ARM64/Windows x64, Core recorded **1,125 passed,
0 skipped** and SourceGen **733 passed, 53 existing gated skips**. Those
skips are not passes; configuration counts are not summed into a
unique-test total. This source does not include the separate metadata
correction in #40252. Completed unit XML evidence remains valid despite
cancellation; it does not establish a full build, pack, integration, UI,
or device-test pass.

The human-requested replacement runs use the **same synthetic merge**.
They were initially confirmed **in progress**; the later terminal
UI/device status and remaining main-pipeline coverage are recorded
below:

| Pipeline | Existing replacement run | Queued (UTC) |
| --- | --- | --- |
| `maui-pr` |
[1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489)
| 16:45:42 |
| `maui-pr-uitests` |
[1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
| 16:45:45 |
| `maui-pr-devicetests` |
[1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
| 16:45:48 |

Reuse those runs; no additional pipelines or reviews were queued for
this description update. The native causal chain and original local **77
passed / 0 failed / 0 skipped** result above remain separate evidence,
not replacement-CI results.

The human-requested `maui-copilot` review gate
[16033607](https://dev.azure.com/DevDiv/DevDiv/_build/results?buildId=16033607)
is
**[INCONCLUSIVE](#40258 (comment):
provisioning stopped before verifying/checking out the PR head,
establishing a baseline, or running tests. Its trusted runner source
`e1140933230eabacbaf6412c0b8d80ece38f2d48` is not the tested PR source.
Original Azure raw log 12 contains 32 physical lines; lines 13, 21, and
29 repeat the protection refusal across the three existing setup
attempts: "The new servicing/staging target must have branch protection
before credential-bearing provisioning can run. Refusing to switch."
GitHub independently reports `candidate/11.0.1xx-sr2` as
`protected=false`.

This gate supplied **no test execution or causal-baseline result**. It
is not a test-red verdict or evidence against the sample fix. Deploying
the required candidate branch protection is a **maintainer action**; do
not bypass or modify the guard. Full replacement-CI outcomes and a
successfully provisioned review gate remain outstanding.

**Later CI/review evidence (2026-11-14 UTC)**

[Expert review
5905946810](#40258 (review))
reviewed exact head `026e646e5f820804ca655813a9a5c0e83e40e115` and
reported **zero findings**. Its state is `COMMENTED`, not human approval
or a successful runtime gate. Candidate protection is still `false`; the
provisioning gate described above remains blocked.

In [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
at the same `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` merge, the
**CoreCLR device-test build failed before runtime execution**. Original
raw log 63 records nine CA1416 diagnostics while compiling Essentials
`net11.0-ios27.0`: three deprecated `UIGraphics` calls in
`MediaPicker/ImageProcessor.ios.cs` and six availability calls in
`Passkeys/Passkeys.ios.cs`. The original binlog confirms those nine
diagnostics plus one outer `BuildFailed`, not independent faults in
every downstream project. Three dependent CoreCLR runtime stages were
skipped, leaving a coverage gap.

Those two Essentials source files are byte-identical on the target and
candidate. The actual candidate control [device run
1681310](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681310),
source `77a87edc03aa2728d7e0a51050da0e424a82c801`, completed the CoreCLR
build successfully with zero errors (original raw log 67). This build
failure is unrelated to the sample's one XAML attribute; the precise
analyzer-input divergence remains **unproven**. No speculative
availability/source fix or analyzer suppression is proposed.

Completed portions of [replacement UI run
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490),
on the same merge, supply separate unchanged MacCatalyst evidence:
CollectionView7 run **46901196** recorded **52 passed, 0 skipped**,
including both #31899 header/footer cases, with no retry; mixed drag
shard run **46901170** recorded **57 passed, 1 existing skip**,
including the #12060 and #28416 cases, with no retry. These are not
evidence of a causal MacCatalyst repair by this Android
incremental-sample change.

The MacCatalyst Navigation shard still has **two failures on both the
original attempt and existing retry**: #21814 receives an empty
navigation-event string, and #23902 receives "NavigatedTo called 2
times" instead of 3. Original raw log 3790 and publisher log 3792
correlate to run **46901248** (**85 passed, 2 failed, 1 skipped**);
failure details are
[#21814](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087)
and
[#23902](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086).
These repeat separately observed candidate/branch failures and are not
attributed to the unrelated sample delta.

The replacement Android `Github5623`/original 77-case CollectionView2 CI
result is published and passed on its first attempt, as detailed below.
Overall UI run **1681490** and device run **1681491** have completed
failed; main run **1681489** remains in progress with passing
Build/Pack/Unit stages and incomplete integration coverage. Keep the
original local causal/full-77 evidence distinct from completed CI shard
results, recovered initial failures, and remaining pipeline outcomes. No
new queues, review replies, source changes, or protection changes were
made.

**Completed exact-source Android CI (2026-11-14 UTC)**

The original API30 CollectionView2 suite completed in [maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
at synthetic merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` (PR head
`026e646e5f820804ca655813a9a5c0e83e40e115`, candidate base
`dca0930d7167052b18c0fa25b1995fa416c2bb06`). [Original run
46901428](https://dev.azure.com/dnceng-public/public/_TestManagement/Runs?runId=46901428&_a=runCharts)
recorded **77 passed, 0 failed, 0 skipped on the first attempt**. The
actual [Github5623(Android).CollectionViewInfiniteScroll result
100042](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901428/Results/100042)
passed in **9,353 ms**, without a harness retry.

Original Azure [raw log
4026](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4026)
contains 1,254 physical lines and the successful 77-pass summary, with
no failed case or harness retry. [Publisher log
4028](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4028)
links those exact 77 results to run 46901428. All 77 automated names and
their multiplicities match actual-candidate original run 46895912; the
selector, original oracle, and 15-second scroll deadline were not
reduced or changed. This closes the previously recorded local
ARM64/GA-versus-CI-servicing runtime gap **for this original Android
suite only**; the local causal chain remains independently documented
above.

This is not a whole-pipeline or other-platform clearance. The two
MacCatalyst Navigation failures above remain. A separate MacCatalyst
[#25074
result](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228)
fails `ButtonResizesWhenTitleOrImageChangesAltered.png` with **1.14%
difference on both the original attempt and existing retry**; it is
unrelated to this sample delta, not an Android-oracle failure. The
CoreCLR availability-build failure and skipped-runtime coverage gap in
device run 1681491 remain; that overall device run has completed
**failed**, as has UI run 1681490. Candidate protection is still
`false`, so the runtime review gate remains blocked despite the
exact-head zero-findings expert review. Main run 1681489 has passing
Build/Pack/Unit stages, but its incomplete Integration stage prevents a
whole-main pass. The full terminal UI and measured integration scopes
are detailed below. No new queues, review replies, source changes, or
protection changes were made.

**Terminal UI audit and remaining validation (2026-11-14 UTC)**

[maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
has completed **failed** at exact merge
`b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. All **129 original UI task
raw logs**, their own publishers, and **129 actual final result sets**
were audited. Final published records across platforms/categories are
**14,907 passed, 302 NotExecuted, 3 failed**. These are execution
records, **not unique methods or first-attempt green results**. Nineteen
eventually successful tasks retain **71 original failed records** in
their raw logs; retry recovery does not erase those failures or
establish causal repairs. Every raw failure method name appears in a
corresponding final run, but this is a method-name presence check, not a
claim of fully qualified oracle identity equivalence.

The only three final failures are the MacCatalyst cases already
documented: [#25074's 1.14% altered-button
snapshot](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228),
[#23902's two-versus-three navigation
count](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086),
and [#21814's empty navigation-event
text](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087).
The original Android API30 CollectionView2 suite above remains **77
passed, 0 failed, 0 skipped on its first attempt, with no harness
retry**; the full terminal audit independently preserves its original
log 4026, publisher 4028, and run 46901428. The unrelated Mac failures
do not invalidate that exact Android result.

[maui-pr
1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489),
on the same merge, now has completed passing **Build, Pack, and Helix
Unit Test stages**, but **the whole pipeline is not yet passed**. Only
**20 of 23 original integration tasks** have completed measured
summaries: **311 passed, 10 existing skips, 0 failed** in those
completed tasks. Three tasks remain unmeasured/in progress:
`mac_buildtemplate_previous_tests`, Windows `Build`, and Windows
`Blazor`. Their absent results are not zero failures or passes.

Terminal [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
remains **failed**. Its **31 available product XML reports** contain
**22,318 passed, 2 existing Windows Border failures, 549 existing
skips**, with available per-assembly counts checked and no
assembly-error/count gaps. Skip identities, reasons, and multiplicities
match the candidate; counts span available execution/configuration
records, not unique methods. The nine-CA1416 CoreCLR compile failure and
three skipped dependent runtime stages remain a separate coverage gap:
available XML results do not certify the missing CoreCLR matrix.

The PR head, candidate base, and synthetic merge are unchanged.
Candidate protection remains `false`, the provisioning review gate
remains blocked, and zero-findings expert review is still not human
approval or runtime-gate success. No source changes, pushes, new queues,
review replies, or protection changes were made for this validation
update.

**Exact validation commands and results**

```sh
# Passed: Android-only repository build tasks.
dotnet build ./Microsoft.Maui.BuildTasks.slnf -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:BuildTaskOnlyBuild=true -v:q -nologo

# Passed for original, diagnostic control, fixed, reverted, restored, and immutable-head builds.
dotnet build src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj -c Release -f net11.0-android -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:RuntimeIdentifier=android-arm64 -p:EmbedAssembliesIntoApk=true -v:q -nologo

# Passed: original Android NUnit runner, with private transport only.
dotnet build src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -v:q -nologo

# Same command for each original-oracle phase; $resultdir selected a separate retained phase/attempt directory.
# Results are the actual cases in the phase table above; no automatic test retry was added.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE="$resultdir/appium.log" dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'Name=CollectionViewInfiniteScroll' --logger 'trx;LogFileName=original.trx' --results-directory "$resultdir" -v:q -nologo -- "NUnit.TestOutputXml=$resultdir/nunit"

# Passed: original 77-case selector, after pushing and verifying the exact immutable head.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/appium.log dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'TestCategory=CollectionView2' --logger 'trx;LogFileName=collectionview2.trx' --results-directory /Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2 -v:q -nologo -- NUnit.TestOutputXml=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/nunit

# Passed.
xmllint --noout src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml
# Passed.
git diff --check

# Not completed: bounded/stopped during full-solution loading without output; no formatting pass claimed.
# Only XAML changed; native XAML compilation and XML syntax checks above passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml --verify-no-changes --verbosity quiet
```

Direct source build/install/NUnit commands mirror the existing Cake
UI-test recipe and deliberately avoid the local wrapper's global ADB
restart/recovery behavior in this shared environment. Pre-existing
emulators and their ADB server were preserved.

### 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. -->

Relates to #40116, #39491, and #40227. These references are
intentionally non-closing; this corrects the incremental-loading
sample's scroll-mode contract.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 22, 2026
…ection update (#39491)

<!-- 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 Details

When the `ItemsUpdatingScrollMode` is set to `KeepItemsInView,` the
items doesnot scroll to the first item , it maintains the current item

### Root Cause

In the `MauiRecyclerView`, the data change observer is paused for
`KeepItemsInView` in `ItemsUpdatingScrollMode` to maintain the first
position of the item.

### Description of Change

We need to observe the data changes for the `KeepItemsInView` option, as
there may be cases where the item might not remain in view.The issue is
fixed by restarting the data change observer in `MauiRecyclerView`.

### Reference PR : #27153 

### Issues Fixed
Fixes #26810 
Fixes #28006
Fixes #29153
Fixes #29145 

### Tested the behaviour in the following platforms
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

### Output Screenshot
Before Issue Fix | After Issue Fix |
|----------|----------|
|<video width="200" height="200" alt="Before Fix video"
src="https://github.com/user-attachments/assets/8adbd870-9c8f-4ac2-bdf2-93301ef0e073">|<video
width="200" height="200" alt="After Fix video"
src="https://github.com/user-attachments/assets/5edb1a05-2a81-46ba-bb1f-353530b4fbc9">|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 22, 2026
…40227)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, branched from
`41458556cf5d13573a632b83f89072f8badfb205`. No rebase, retarget, product
change, or merge is included.

### Description of Change

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

Correct the stale `KeepItemsInView` UI-test contract exposed by #40116.
The [CollectionView
documentation](https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/collectionview/scrolling.md#control-scroll-position-when-new-items-are-added)
and current enum XML documentation specify keeping the **first item in
the list** displayed. #39491 and #39493 intentionally implement that
behavior. The remaining Apple test instead expected the previously
visible middle item; the Android branch only checked that this old item
disappeared.

Use the same positive assertions on Android, iOS and MacCatalyst,
retaining the existing Windows exclusion and CollectionView shard.
Verify the initial middle item is actually displayed, insert once, and
positively assert that `cover1.jpg, 0` is displayed. Scroll away again
and verify the new middle identity (`photo.jpg, 9`), then perform the
remaining 24 insertions and positively assert the first item again. This
preserves 25 total updates and prevents the second check from passing
merely because the first insertion already scrolled to the top.

The existing sample inserts at `(Count / 2) - 1`, **not** at index zero;
the first item's identity remains unchanged. No sample IDs, product
behavior, `KeepScrollOffset`, `KeepLastItemInView`, timeouts, retries,
skips, screenshots, tolerances, or CI configuration are changed.
Upstream searches found the existing product fixes above but no
competing test-contract correction.

**Native validation**

Used the original `ui-tests-samples-coreclr` HostApp from
[maui-pr-uitests
1678816](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1678816),
source `fd2f3ce40199b5c48e31a1814a23919f41f6c3d3`, on an isolated iPhone
11 Pro **CoreSimulator iOS 26.5**. The gallery, data source, template,
Apple scroll helper, and both Apple layout implementations have no
source diff between that CI source and this branch's candidate base.
This does not claim the entire binary tree is identical. HostApp
executable SHA-256:
`895101edc9254a6e235051f77cd2bc8e72d4646477b1ed4b308d8de86392396c`.

| Native oracle on the unchanged CI app | Result |
| --- | --- |
| Original Apple test, 25 insertions, old middle-item expectation |
Failed at final `WaitForElement("Vegetables.jpg, 10")`, reproducing CI
(42 s) |
| Corrected positive first-item test | Passed 3/3 (29 s, 31 s, 29 s) |
| Negative mutation: expect the old middle item after the first
insertion | Failed at that wrong-target oracle (25 s) |
| Restored corrected test after the negative mutation | Passed 2/2;
included in the 3/3 above |

Exact test command for the first corrected run (passed 1/1; repeated
with separate result/log paths for the other runs):

```sh
DEVICE_UDID=05DEC405-3AC9-4F2E-8DBC-8B75A0CF9F4C PLATFORM_VERSION=26.5 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/appium-corrected.log dotnet test artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net11.0/Controls.TestCases.iOS.Tests.dll --filter 'FullyQualifiedName~KeepItemsInView' --logger 'trx;LogFileName=corrected.trx' --results-directory /Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/native-corrected
```

The native HostApp was **not rebuilt** using the locally installed Xcode
27.2 or SDK-check bypasses. Only the platform-neutral net11.0 NUnit
runner was rebuilt using installed .NET SDK 11.0.100. The artifact route
deliberately avoids the local HostApp runner's source rebuild and
shutdown of other sessions' simulators. An initial overly specific
discovery filter selected zero tests; it was corrected to the command
above before collecting these outcomes.

Exact compilation/formatting commands and results:

```sh
# Passed: iOS NUnit runner, final corrected source.
dotnet msbuild src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Android NUnit runner compilation; not an Android native execution.
dotnet msbuild src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Catalyst NUnit runner compilation; not a Catalyst native execution.
dotnet msbuild src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/CollectionViewUITests.CollectionViewItemsUpdatingScrollMode.cs --verify-no-changes --verbosity quiet
# Passed.
git diff --check
```

Native Android and MacCatalyst execution and full-suite CI are not
claimed. No duplicate candidate-wide CI run was queued; candidate-wide
coverage remains coordinated separately.

### 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. -->

Relates to #40116, #39491, and #39493. These references are
intentionally non-closing; this fixes the test contract, not the
underlying product issues.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 22, 2026
…ng (#40258)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, based on
`dca0930d7167052b18c0fa25b1995fa416c2bb06`. No merge, retarget, rebase,
or manual CI/review request is included.

### Description of Change

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

Make the `Github5623` incremental-loading sample explicitly use
`KeepScrollOffset`. Its implicit `KeepItemsInView` default now
intentionally scrolls to the first item after an insertion (#39491).
That behavior is correct for that mode, but inappropriate for this
sample's continuous user scrolling through asynchronously appended
pages. #40227's documented first-item contract and the production
implementation remain intact.

The original API30 `Github5623(Android).CollectionViewInfiniteScroll`
oracle reproduced the candidate timeout at
`AppiumTouchActions.ScrollTo:333` / original test line 27. Separate
native diagnostics observed successful page appends `10 -> 20 -> 30 ->
40`, each immediately followed by a native zero-delta callback with the
first cell back at index 0/top 0. These rewinds explain the large
cumulative managed scroll offset despite low visible indexes.
Temporarily removing that native rewind as a **diagnostic control only**
eliminated the resets. The native control and all diagnostic code were
then restored and hash-verified before committing.

The committed change is exactly one XAML attribute. The original NUnit
method, discovery of item `12` by actual user gestures, random 20-319
item heights, `MeasureAllItems`, threshold 25, initial/page size 10,
loading implementation, original 15-second `ScrollTo` deadline, waits,
assertions, retries, categories, and screenshots are unchanged. This is
a sample contract correction, not a production rollback or a weakened
test.

Upstream open/recently merged PR searches covered `Github5623`, infinite
scrolling, `KeepItemsInView`, and `KeepScrollOffset`, together with the
exact sample file history. They identified #39491 and #40227 but no
competing sample repair.

**Native evidence**

Used one task-owned API30 Google APIs ARM64 Nexus 5X emulator, 1080x1920
at 420 dpi, with .NET SDK 11.0.100/runtime 11.0.0, source-built Release
HostApp, embedded assemblies, and the original Android NUnit assembly.
Appium transport alone was adapted locally to private ports
4793/8293/7893 and the owned emulator; that adaptation is not committed.
No physical Apple device or host macOS XCTest automation was used.

| Phase | Actual cases | Result |
| --- | --- | --- |
| Unchanged original sample/oracle | 1 | Failed: exact scrolling-to-12
timeout, 18.233251 s |
| Instrumented native trigger-removal control, not the published fix | 1
| Passed, 7.563766 s; appends retained without rewind |
| Non-instrumented sample-only fix | 3 | Passed: 10.791304 / 8.946879 /
8.947579 s |
| Revert only the sample attribute, restore and rebuild original sources
| 1 | Failed: same scrolling-to-12 timeout, 17.930881 s |
| Restore fix, rebuild immutable
`026e646e5f820804ca655813a9a5c0e83e40e115` | 3 | Passed: 8.922002 /
11.637289 / 10.590518 s |
| Unchanged original `TestCategory=CollectionView2` selector on that
pushed immutable head | 77 | **77 passed, 0 failed, 0 skipped**;
original infinite-scroll case passed in 7.278173 s |

Raw TRX and NUnit XML were checked independently and retained for every
invocation. A separate diagnostic run with the original rewind still
enabled passed in 16.054472 s and is **not** counted as a
non-instrumented baseline pass. Five initial zero-test selector
invocations and one Appium argument-quoting setup failure are retained
separately; none establishes an original-oracle outcome.

Immutable-head APK SHA-256:
`1b3cf5c30f5c001919874e540f52183cf41d346a4b7b2bcfa8ab4b1cd687b9f8`.

**Limits:** the local causal chain proves the sample repair on API30
ARM64/.NET 11 GA, and the completed exact-source API30 CI suite below
now supplies CI-servicing confirmation for the original 77-case Android
suite. Other-platform and whole-pipeline clearance are not claimed. The
supplied newest exact-target CI case was green; this PR does not claim
that the latest target was red or that the unrelated managed-unit
correction caused the failure. Candidate-wide CI remains
parent-coordinated.

**CI validation and remaining limits (2026-11-14 UTC snapshot)**

The live PR remains at head `026e646e5f820804ca655813a9a5c0e83e40e115`,
candidate base `dca0930d7167052b18c0fa25b1995fa416c2bb06`, and synthetic
merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. The human-issued
review, rebase, and pipeline requests on November 14 did not change
those source identities.

The earlier [maui-pr
1681455](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681455)
and [maui-pr-uitests
1681457](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681457)
were **canceled**, not complete passing runs. Before cancellation, the
four managed-unit Helix jobs completed and all **50 product work-item
XML reports** were audited, excluding controller work items, with no
named failures, assembly errors, or XML/count gaps. In each of
Debug/Release on macOS ARM64/Windows x64, Core recorded **1,125 passed,
0 skipped** and SourceGen **733 passed, 53 existing gated skips**. Those
skips are not passes; configuration counts are not summed into a
unique-test total. This source does not include the separate metadata
correction in #40252. Completed unit XML evidence remains valid despite
cancellation; it does not establish a full build, pack, integration, UI,
or device-test pass.

The human-requested replacement runs use the **same synthetic merge**.
They were initially confirmed **in progress**; the later terminal
UI/device status and remaining main-pipeline coverage are recorded
below:

| Pipeline | Existing replacement run | Queued (UTC) |
| --- | --- | --- |
| `maui-pr` |
[1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489)
| 16:45:42 |
| `maui-pr-uitests` |
[1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
| 16:45:45 |
| `maui-pr-devicetests` |
[1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
| 16:45:48 |

Reuse those runs; no additional pipelines or reviews were queued for
this description update. The native causal chain and original local **77
passed / 0 failed / 0 skipped** result above remain separate evidence,
not replacement-CI results.

The human-requested `maui-copilot` review gate
[16033607](https://dev.azure.com/DevDiv/DevDiv/_build/results?buildId=16033607)
is
**[INCONCLUSIVE](#40258 (comment):
provisioning stopped before verifying/checking out the PR head,
establishing a baseline, or running tests. Its trusted runner source
`e1140933230eabacbaf6412c0b8d80ece38f2d48` is not the tested PR source.
Original Azure raw log 12 contains 32 physical lines; lines 13, 21, and
29 repeat the protection refusal across the three existing setup
attempts: "The new servicing/staging target must have branch protection
before credential-bearing provisioning can run. Refusing to switch."
GitHub independently reports `candidate/11.0.1xx-sr2` as
`protected=false`.

This gate supplied **no test execution or causal-baseline result**. It
is not a test-red verdict or evidence against the sample fix. Deploying
the required candidate branch protection is a **maintainer action**; do
not bypass or modify the guard. Full replacement-CI outcomes and a
successfully provisioned review gate remain outstanding.

**Later CI/review evidence (2026-11-14 UTC)**

[Expert review
5905946810](#40258 (review))
reviewed exact head `026e646e5f820804ca655813a9a5c0e83e40e115` and
reported **zero findings**. Its state is `COMMENTED`, not human approval
or a successful runtime gate. Candidate protection is still `false`; the
provisioning gate described above remains blocked.

In [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
at the same `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` merge, the
**CoreCLR device-test build failed before runtime execution**. Original
raw log 63 records nine CA1416 diagnostics while compiling Essentials
`net11.0-ios27.0`: three deprecated `UIGraphics` calls in
`MediaPicker/ImageProcessor.ios.cs` and six availability calls in
`Passkeys/Passkeys.ios.cs`. The original binlog confirms those nine
diagnostics plus one outer `BuildFailed`, not independent faults in
every downstream project. Three dependent CoreCLR runtime stages were
skipped, leaving a coverage gap.

Those two Essentials source files are byte-identical on the target and
candidate. The actual candidate control [device run
1681310](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681310),
source `77a87edc03aa2728d7e0a51050da0e424a82c801`, completed the CoreCLR
build successfully with zero errors (original raw log 67). This build
failure is unrelated to the sample's one XAML attribute; the precise
analyzer-input divergence remains **unproven**. No speculative
availability/source fix or analyzer suppression is proposed.

Completed portions of [replacement UI run
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490),
on the same merge, supply separate unchanged MacCatalyst evidence:
CollectionView7 run **46901196** recorded **52 passed, 0 skipped**,
including both #31899 header/footer cases, with no retry; mixed drag
shard run **46901170** recorded **57 passed, 1 existing skip**,
including the #12060 and #28416 cases, with no retry. These are not
evidence of a causal MacCatalyst repair by this Android
incremental-sample change.

The MacCatalyst Navigation shard still has **two failures on both the
original attempt and existing retry**: #21814 receives an empty
navigation-event string, and #23902 receives "NavigatedTo called 2
times" instead of 3. Original raw log 3790 and publisher log 3792
correlate to run **46901248** (**85 passed, 2 failed, 1 skipped**);
failure details are
[#21814](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087)
and
[#23902](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086).
These repeat separately observed candidate/branch failures and are not
attributed to the unrelated sample delta.

The replacement Android `Github5623`/original 77-case CollectionView2 CI
result is published and passed on its first attempt, as detailed below.
Overall UI run **1681490** and device run **1681491** have completed
failed; main run **1681489** remains in progress with passing
Build/Pack/Unit stages and incomplete integration coverage. Keep the
original local causal/full-77 evidence distinct from completed CI shard
results, recovered initial failures, and remaining pipeline outcomes. No
new queues, review replies, source changes, or protection changes were
made.

**Completed exact-source Android CI (2026-11-14 UTC)**

The original API30 CollectionView2 suite completed in [maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
at synthetic merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` (PR head
`026e646e5f820804ca655813a9a5c0e83e40e115`, candidate base
`dca0930d7167052b18c0fa25b1995fa416c2bb06`). [Original run
46901428](https://dev.azure.com/dnceng-public/public/_TestManagement/Runs?runId=46901428&_a=runCharts)
recorded **77 passed, 0 failed, 0 skipped on the first attempt**. The
actual [Github5623(Android).CollectionViewInfiniteScroll result
100042](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901428/Results/100042)
passed in **9,353 ms**, without a harness retry.

Original Azure [raw log
4026](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4026)
contains 1,254 physical lines and the successful 77-pass summary, with
no failed case or harness retry. [Publisher log
4028](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4028)
links those exact 77 results to run 46901428. All 77 automated names and
their multiplicities match actual-candidate original run 46895912; the
selector, original oracle, and 15-second scroll deadline were not
reduced or changed. This closes the previously recorded local
ARM64/GA-versus-CI-servicing runtime gap **for this original Android
suite only**; the local causal chain remains independently documented
above.

This is not a whole-pipeline or other-platform clearance. The two
MacCatalyst Navigation failures above remain. A separate MacCatalyst
[#25074
result](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228)
fails `ButtonResizesWhenTitleOrImageChangesAltered.png` with **1.14%
difference on both the original attempt and existing retry**; it is
unrelated to this sample delta, not an Android-oracle failure. The
CoreCLR availability-build failure and skipped-runtime coverage gap in
device run 1681491 remain; that overall device run has completed
**failed**, as has UI run 1681490. Candidate protection is still
`false`, so the runtime review gate remains blocked despite the
exact-head zero-findings expert review. Main run 1681489 has passing
Build/Pack/Unit stages, but its incomplete Integration stage prevents a
whole-main pass. The full terminal UI and measured integration scopes
are detailed below. No new queues, review replies, source changes, or
protection changes were made.

**Terminal UI audit and remaining validation (2026-11-14 UTC)**

[maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
has completed **failed** at exact merge
`b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. All **129 original UI task
raw logs**, their own publishers, and **129 actual final result sets**
were audited. Final published records across platforms/categories are
**14,907 passed, 302 NotExecuted, 3 failed**. These are execution
records, **not unique methods or first-attempt green results**. Nineteen
eventually successful tasks retain **71 original failed records** in
their raw logs; retry recovery does not erase those failures or
establish causal repairs. Every raw failure method name appears in a
corresponding final run, but this is a method-name presence check, not a
claim of fully qualified oracle identity equivalence.

The only three final failures are the MacCatalyst cases already
documented: [#25074's 1.14% altered-button
snapshot](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228),
[#23902's two-versus-three navigation
count](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086),
and [#21814's empty navigation-event
text](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087).
The original Android API30 CollectionView2 suite above remains **77
passed, 0 failed, 0 skipped on its first attempt, with no harness
retry**; the full terminal audit independently preserves its original
log 4026, publisher 4028, and run 46901428. The unrelated Mac failures
do not invalidate that exact Android result.

[maui-pr
1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489),
on the same merge, now has completed passing **Build, Pack, and Helix
Unit Test stages**, but **the whole pipeline is not yet passed**. Only
**20 of 23 original integration tasks** have completed measured
summaries: **311 passed, 10 existing skips, 0 failed** in those
completed tasks. Three tasks remain unmeasured/in progress:
`mac_buildtemplate_previous_tests`, Windows `Build`, and Windows
`Blazor`. Their absent results are not zero failures or passes.

Terminal [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
remains **failed**. Its **31 available product XML reports** contain
**22,318 passed, 2 existing Windows Border failures, 549 existing
skips**, with available per-assembly counts checked and no
assembly-error/count gaps. Skip identities, reasons, and multiplicities
match the candidate; counts span available execution/configuration
records, not unique methods. The nine-CA1416 CoreCLR compile failure and
three skipped dependent runtime stages remain a separate coverage gap:
available XML results do not certify the missing CoreCLR matrix.

The PR head, candidate base, and synthetic merge are unchanged.
Candidate protection remains `false`, the provisioning review gate
remains blocked, and zero-findings expert review is still not human
approval or runtime-gate success. No source changes, pushes, new queues,
review replies, or protection changes were made for this validation
update.

**Exact validation commands and results**

```sh
# Passed: Android-only repository build tasks.
dotnet build ./Microsoft.Maui.BuildTasks.slnf -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:BuildTaskOnlyBuild=true -v:q -nologo

# Passed for original, diagnostic control, fixed, reverted, restored, and immutable-head builds.
dotnet build src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj -c Release -f net11.0-android -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:RuntimeIdentifier=android-arm64 -p:EmbedAssembliesIntoApk=true -v:q -nologo

# Passed: original Android NUnit runner, with private transport only.
dotnet build src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -v:q -nologo

# Same command for each original-oracle phase; $resultdir selected a separate retained phase/attempt directory.
# Results are the actual cases in the phase table above; no automatic test retry was added.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE="$resultdir/appium.log" dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'Name=CollectionViewInfiniteScroll' --logger 'trx;LogFileName=original.trx' --results-directory "$resultdir" -v:q -nologo -- "NUnit.TestOutputXml=$resultdir/nunit"

# Passed: original 77-case selector, after pushing and verifying the exact immutable head.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/appium.log dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'TestCategory=CollectionView2' --logger 'trx;LogFileName=collectionview2.trx' --results-directory /Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2 -v:q -nologo -- NUnit.TestOutputXml=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/nunit

# Passed.
xmllint --noout src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml
# Passed.
git diff --check

# Not completed: bounded/stopped during full-solution loading without output; no formatting pass claimed.
# Only XAML changed; native XAML compilation and XML syntax checks above passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml --verify-no-changes --verbosity quiet
```

Direct source build/install/NUnit commands mirror the existing Cake
UI-test recipe and deliberately avoid the local wrapper's global ADB
restart/recovery behavior in this shared environment. Pre-existing
emulators and their ADB server were preserved.

### 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. -->

Relates to #40116, #39491, and #40227. These references are
intentionally non-closing; this corrects the incremental-loading
sample's scroll-mode contract.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 23, 2026
…ection update (#39491)

<!-- 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 Details

When the `ItemsUpdatingScrollMode` is set to `KeepItemsInView,` the
items doesnot scroll to the first item , it maintains the current item

### Root Cause

In the `MauiRecyclerView`, the data change observer is paused for
`KeepItemsInView` in `ItemsUpdatingScrollMode` to maintain the first
position of the item.

### Description of Change

We need to observe the data changes for the `KeepItemsInView` option, as
there may be cases where the item might not remain in view.The issue is
fixed by restarting the data change observer in `MauiRecyclerView`.

### Reference PR : #27153 

### Issues Fixed
Fixes #26810 
Fixes #28006
Fixes #29153
Fixes #29145 

### Tested the behaviour in the following platforms
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

### Output Screenshot
Before Issue Fix | After Issue Fix |
|----------|----------|
|<video width="200" height="200" alt="Before Fix video"
src="https://github.com/user-attachments/assets/8adbd870-9c8f-4ac2-bdf2-93301ef0e073">|<video
width="200" height="200" alt="After Fix video"
src="https://github.com/user-attachments/assets/5edb1a05-2a81-46ba-bb1f-353530b4fbc9">|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 23, 2026
…40227)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, branched from
`41458556cf5d13573a632b83f89072f8badfb205`. No rebase, retarget, product
change, or merge is included.

### Description of Change

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

Correct the stale `KeepItemsInView` UI-test contract exposed by #40116.
The [CollectionView
documentation](https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/collectionview/scrolling.md#control-scroll-position-when-new-items-are-added)
and current enum XML documentation specify keeping the **first item in
the list** displayed. #39491 and #39493 intentionally implement that
behavior. The remaining Apple test instead expected the previously
visible middle item; the Android branch only checked that this old item
disappeared.

Use the same positive assertions on Android, iOS and MacCatalyst,
retaining the existing Windows exclusion and CollectionView shard.
Verify the initial middle item is actually displayed, insert once, and
positively assert that `cover1.jpg, 0` is displayed. Scroll away again
and verify the new middle identity (`photo.jpg, 9`), then perform the
remaining 24 insertions and positively assert the first item again. This
preserves 25 total updates and prevents the second check from passing
merely because the first insertion already scrolled to the top.

The existing sample inserts at `(Count / 2) - 1`, **not** at index zero;
the first item's identity remains unchanged. No sample IDs, product
behavior, `KeepScrollOffset`, `KeepLastItemInView`, timeouts, retries,
skips, screenshots, tolerances, or CI configuration are changed.
Upstream searches found the existing product fixes above but no
competing test-contract correction.

**Native validation**

Used the original `ui-tests-samples-coreclr` HostApp from
[maui-pr-uitests
1678816](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1678816),
source `fd2f3ce40199b5c48e31a1814a23919f41f6c3d3`, on an isolated iPhone
11 Pro **CoreSimulator iOS 26.5**. The gallery, data source, template,
Apple scroll helper, and both Apple layout implementations have no
source diff between that CI source and this branch's candidate base.
This does not claim the entire binary tree is identical. HostApp
executable SHA-256:
`895101edc9254a6e235051f77cd2bc8e72d4646477b1ed4b308d8de86392396c`.

| Native oracle on the unchanged CI app | Result |
| --- | --- |
| Original Apple test, 25 insertions, old middle-item expectation |
Failed at final `WaitForElement("Vegetables.jpg, 10")`, reproducing CI
(42 s) |
| Corrected positive first-item test | Passed 3/3 (29 s, 31 s, 29 s) |
| Negative mutation: expect the old middle item after the first
insertion | Failed at that wrong-target oracle (25 s) |
| Restored corrected test after the negative mutation | Passed 2/2;
included in the 3/3 above |

Exact test command for the first corrected run (passed 1/1; repeated
with separate result/log paths for the other runs):

```sh
DEVICE_UDID=05DEC405-3AC9-4F2E-8DBC-8B75A0CF9F4C PLATFORM_VERSION=26.5 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/appium-corrected.log dotnet test artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net11.0/Controls.TestCases.iOS.Tests.dll --filter 'FullyQualifiedName~KeepItemsInView' --logger 'trx;LogFileName=corrected.trx' --results-directory /Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/native-corrected
```

The native HostApp was **not rebuilt** using the locally installed Xcode
27.2 or SDK-check bypasses. Only the platform-neutral net11.0 NUnit
runner was rebuilt using installed .NET SDK 11.0.100. The artifact route
deliberately avoids the local HostApp runner's source rebuild and
shutdown of other sessions' simulators. An initial overly specific
discovery filter selected zero tests; it was corrected to the command
above before collecting these outcomes.

Exact compilation/formatting commands and results:

```sh
# Passed: iOS NUnit runner, final corrected source.
dotnet msbuild src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Android NUnit runner compilation; not an Android native execution.
dotnet msbuild src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Catalyst NUnit runner compilation; not a Catalyst native execution.
dotnet msbuild src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/CollectionViewUITests.CollectionViewItemsUpdatingScrollMode.cs --verify-no-changes --verbosity quiet
# Passed.
git diff --check
```

Native Android and MacCatalyst execution and full-suite CI are not
claimed. No duplicate candidate-wide CI run was queued; candidate-wide
coverage remains coordinated separately.

### 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. -->

Relates to #40116, #39491, and #39493. These references are
intentionally non-closing; this fixes the test contract, not the
underlying product issues.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 23, 2026
…ng (#40258)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, based on
`dca0930d7167052b18c0fa25b1995fa416c2bb06`. No merge, retarget, rebase,
or manual CI/review request is included.

### Description of Change

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

Make the `Github5623` incremental-loading sample explicitly use
`KeepScrollOffset`. Its implicit `KeepItemsInView` default now
intentionally scrolls to the first item after an insertion (#39491).
That behavior is correct for that mode, but inappropriate for this
sample's continuous user scrolling through asynchronously appended
pages. #40227's documented first-item contract and the production
implementation remain intact.

The original API30 `Github5623(Android).CollectionViewInfiniteScroll`
oracle reproduced the candidate timeout at
`AppiumTouchActions.ScrollTo:333` / original test line 27. Separate
native diagnostics observed successful page appends `10 -> 20 -> 30 ->
40`, each immediately followed by a native zero-delta callback with the
first cell back at index 0/top 0. These rewinds explain the large
cumulative managed scroll offset despite low visible indexes.
Temporarily removing that native rewind as a **diagnostic control only**
eliminated the resets. The native control and all diagnostic code were
then restored and hash-verified before committing.

The committed change is exactly one XAML attribute. The original NUnit
method, discovery of item `12` by actual user gestures, random 20-319
item heights, `MeasureAllItems`, threshold 25, initial/page size 10,
loading implementation, original 15-second `ScrollTo` deadline, waits,
assertions, retries, categories, and screenshots are unchanged. This is
a sample contract correction, not a production rollback or a weakened
test.

Upstream open/recently merged PR searches covered `Github5623`, infinite
scrolling, `KeepItemsInView`, and `KeepScrollOffset`, together with the
exact sample file history. They identified #39491 and #40227 but no
competing sample repair.

**Native evidence**

Used one task-owned API30 Google APIs ARM64 Nexus 5X emulator, 1080x1920
at 420 dpi, with .NET SDK 11.0.100/runtime 11.0.0, source-built Release
HostApp, embedded assemblies, and the original Android NUnit assembly.
Appium transport alone was adapted locally to private ports
4793/8293/7893 and the owned emulator; that adaptation is not committed.
No physical Apple device or host macOS XCTest automation was used.

| Phase | Actual cases | Result |
| --- | --- | --- |
| Unchanged original sample/oracle | 1 | Failed: exact scrolling-to-12
timeout, 18.233251 s |
| Instrumented native trigger-removal control, not the published fix | 1
| Passed, 7.563766 s; appends retained without rewind |
| Non-instrumented sample-only fix | 3 | Passed: 10.791304 / 8.946879 /
8.947579 s |
| Revert only the sample attribute, restore and rebuild original sources
| 1 | Failed: same scrolling-to-12 timeout, 17.930881 s |
| Restore fix, rebuild immutable
`026e646e5f820804ca655813a9a5c0e83e40e115` | 3 | Passed: 8.922002 /
11.637289 / 10.590518 s |
| Unchanged original `TestCategory=CollectionView2` selector on that
pushed immutable head | 77 | **77 passed, 0 failed, 0 skipped**;
original infinite-scroll case passed in 7.278173 s |

Raw TRX and NUnit XML were checked independently and retained for every
invocation. A separate diagnostic run with the original rewind still
enabled passed in 16.054472 s and is **not** counted as a
non-instrumented baseline pass. Five initial zero-test selector
invocations and one Appium argument-quoting setup failure are retained
separately; none establishes an original-oracle outcome.

Immutable-head APK SHA-256:
`1b3cf5c30f5c001919874e540f52183cf41d346a4b7b2bcfa8ab4b1cd687b9f8`.

**Limits:** the local causal chain proves the sample repair on API30
ARM64/.NET 11 GA, and the completed exact-source API30 CI suite below
now supplies CI-servicing confirmation for the original 77-case Android
suite. Other-platform and whole-pipeline clearance are not claimed. The
supplied newest exact-target CI case was green; this PR does not claim
that the latest target was red or that the unrelated managed-unit
correction caused the failure. Candidate-wide CI remains
parent-coordinated.

**CI validation and remaining limits (2026-11-14 UTC snapshot)**

The live PR remains at head `026e646e5f820804ca655813a9a5c0e83e40e115`,
candidate base `dca0930d7167052b18c0fa25b1995fa416c2bb06`, and synthetic
merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. The human-issued
review, rebase, and pipeline requests on November 14 did not change
those source identities.

The earlier [maui-pr
1681455](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681455)
and [maui-pr-uitests
1681457](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681457)
were **canceled**, not complete passing runs. Before cancellation, the
four managed-unit Helix jobs completed and all **50 product work-item
XML reports** were audited, excluding controller work items, with no
named failures, assembly errors, or XML/count gaps. In each of
Debug/Release on macOS ARM64/Windows x64, Core recorded **1,125 passed,
0 skipped** and SourceGen **733 passed, 53 existing gated skips**. Those
skips are not passes; configuration counts are not summed into a
unique-test total. This source does not include the separate metadata
correction in #40252. Completed unit XML evidence remains valid despite
cancellation; it does not establish a full build, pack, integration, UI,
or device-test pass.

The human-requested replacement runs use the **same synthetic merge**.
They were initially confirmed **in progress**; the later terminal
UI/device status and remaining main-pipeline coverage are recorded
below:

| Pipeline | Existing replacement run | Queued (UTC) |
| --- | --- | --- |
| `maui-pr` |
[1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489)
| 16:45:42 |
| `maui-pr-uitests` |
[1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
| 16:45:45 |
| `maui-pr-devicetests` |
[1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
| 16:45:48 |

Reuse those runs; no additional pipelines or reviews were queued for
this description update. The native causal chain and original local **77
passed / 0 failed / 0 skipped** result above remain separate evidence,
not replacement-CI results.

The human-requested `maui-copilot` review gate
[16033607](https://dev.azure.com/DevDiv/DevDiv/_build/results?buildId=16033607)
is
**[INCONCLUSIVE](#40258 (comment):
provisioning stopped before verifying/checking out the PR head,
establishing a baseline, or running tests. Its trusted runner source
`e1140933230eabacbaf6412c0b8d80ece38f2d48` is not the tested PR source.
Original Azure raw log 12 contains 32 physical lines; lines 13, 21, and
29 repeat the protection refusal across the three existing setup
attempts: "The new servicing/staging target must have branch protection
before credential-bearing provisioning can run. Refusing to switch."
GitHub independently reports `candidate/11.0.1xx-sr2` as
`protected=false`.

This gate supplied **no test execution or causal-baseline result**. It
is not a test-red verdict or evidence against the sample fix. Deploying
the required candidate branch protection is a **maintainer action**; do
not bypass or modify the guard. Full replacement-CI outcomes and a
successfully provisioned review gate remain outstanding.

**Later CI/review evidence (2026-11-14 UTC)**

[Expert review
5905946810](#40258 (review))
reviewed exact head `026e646e5f820804ca655813a9a5c0e83e40e115` and
reported **zero findings**. Its state is `COMMENTED`, not human approval
or a successful runtime gate. Candidate protection is still `false`; the
provisioning gate described above remains blocked.

In [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
at the same `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` merge, the
**CoreCLR device-test build failed before runtime execution**. Original
raw log 63 records nine CA1416 diagnostics while compiling Essentials
`net11.0-ios27.0`: three deprecated `UIGraphics` calls in
`MediaPicker/ImageProcessor.ios.cs` and six availability calls in
`Passkeys/Passkeys.ios.cs`. The original binlog confirms those nine
diagnostics plus one outer `BuildFailed`, not independent faults in
every downstream project. Three dependent CoreCLR runtime stages were
skipped, leaving a coverage gap.

Those two Essentials source files are byte-identical on the target and
candidate. The actual candidate control [device run
1681310](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681310),
source `77a87edc03aa2728d7e0a51050da0e424a82c801`, completed the CoreCLR
build successfully with zero errors (original raw log 67). This build
failure is unrelated to the sample's one XAML attribute; the precise
analyzer-input divergence remains **unproven**. No speculative
availability/source fix or analyzer suppression is proposed.

Completed portions of [replacement UI run
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490),
on the same merge, supply separate unchanged MacCatalyst evidence:
CollectionView7 run **46901196** recorded **52 passed, 0 skipped**,
including both #31899 header/footer cases, with no retry; mixed drag
shard run **46901170** recorded **57 passed, 1 existing skip**,
including the #12060 and #28416 cases, with no retry. These are not
evidence of a causal MacCatalyst repair by this Android
incremental-sample change.

The MacCatalyst Navigation shard still has **two failures on both the
original attempt and existing retry**: #21814 receives an empty
navigation-event string, and #23902 receives "NavigatedTo called 2
times" instead of 3. Original raw log 3790 and publisher log 3792
correlate to run **46901248** (**85 passed, 2 failed, 1 skipped**);
failure details are
[#21814](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087)
and
[#23902](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086).
These repeat separately observed candidate/branch failures and are not
attributed to the unrelated sample delta.

The replacement Android `Github5623`/original 77-case CollectionView2 CI
result is published and passed on its first attempt, as detailed below.
Overall UI run **1681490** and device run **1681491** have completed
failed; main run **1681489** remains in progress with passing
Build/Pack/Unit stages and incomplete integration coverage. Keep the
original local causal/full-77 evidence distinct from completed CI shard
results, recovered initial failures, and remaining pipeline outcomes. No
new queues, review replies, source changes, or protection changes were
made.

**Completed exact-source Android CI (2026-11-14 UTC)**

The original API30 CollectionView2 suite completed in [maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
at synthetic merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` (PR head
`026e646e5f820804ca655813a9a5c0e83e40e115`, candidate base
`dca0930d7167052b18c0fa25b1995fa416c2bb06`). [Original run
46901428](https://dev.azure.com/dnceng-public/public/_TestManagement/Runs?runId=46901428&_a=runCharts)
recorded **77 passed, 0 failed, 0 skipped on the first attempt**. The
actual [Github5623(Android).CollectionViewInfiniteScroll result
100042](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901428/Results/100042)
passed in **9,353 ms**, without a harness retry.

Original Azure [raw log
4026](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4026)
contains 1,254 physical lines and the successful 77-pass summary, with
no failed case or harness retry. [Publisher log
4028](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4028)
links those exact 77 results to run 46901428. All 77 automated names and
their multiplicities match actual-candidate original run 46895912; the
selector, original oracle, and 15-second scroll deadline were not
reduced or changed. This closes the previously recorded local
ARM64/GA-versus-CI-servicing runtime gap **for this original Android
suite only**; the local causal chain remains independently documented
above.

This is not a whole-pipeline or other-platform clearance. The two
MacCatalyst Navigation failures above remain. A separate MacCatalyst
[#25074
result](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228)
fails `ButtonResizesWhenTitleOrImageChangesAltered.png` with **1.14%
difference on both the original attempt and existing retry**; it is
unrelated to this sample delta, not an Android-oracle failure. The
CoreCLR availability-build failure and skipped-runtime coverage gap in
device run 1681491 remain; that overall device run has completed
**failed**, as has UI run 1681490. Candidate protection is still
`false`, so the runtime review gate remains blocked despite the
exact-head zero-findings expert review. Main run 1681489 has passing
Build/Pack/Unit stages, but its incomplete Integration stage prevents a
whole-main pass. The full terminal UI and measured integration scopes
are detailed below. No new queues, review replies, source changes, or
protection changes were made.

**Terminal UI audit and remaining validation (2026-11-14 UTC)**

[maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
has completed **failed** at exact merge
`b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. All **129 original UI task
raw logs**, their own publishers, and **129 actual final result sets**
were audited. Final published records across platforms/categories are
**14,907 passed, 302 NotExecuted, 3 failed**. These are execution
records, **not unique methods or first-attempt green results**. Nineteen
eventually successful tasks retain **71 original failed records** in
their raw logs; retry recovery does not erase those failures or
establish causal repairs. Every raw failure method name appears in a
corresponding final run, but this is a method-name presence check, not a
claim of fully qualified oracle identity equivalence.

The only three final failures are the MacCatalyst cases already
documented: [#25074's 1.14% altered-button
snapshot](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228),
[#23902's two-versus-three navigation
count](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086),
and [#21814's empty navigation-event
text](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087).
The original Android API30 CollectionView2 suite above remains **77
passed, 0 failed, 0 skipped on its first attempt, with no harness
retry**; the full terminal audit independently preserves its original
log 4026, publisher 4028, and run 46901428. The unrelated Mac failures
do not invalidate that exact Android result.

[maui-pr
1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489),
on the same merge, now has completed passing **Build, Pack, and Helix
Unit Test stages**, but **the whole pipeline is not yet passed**. Only
**20 of 23 original integration tasks** have completed measured
summaries: **311 passed, 10 existing skips, 0 failed** in those
completed tasks. Three tasks remain unmeasured/in progress:
`mac_buildtemplate_previous_tests`, Windows `Build`, and Windows
`Blazor`. Their absent results are not zero failures or passes.

Terminal [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
remains **failed**. Its **31 available product XML reports** contain
**22,318 passed, 2 existing Windows Border failures, 549 existing
skips**, with available per-assembly counts checked and no
assembly-error/count gaps. Skip identities, reasons, and multiplicities
match the candidate; counts span available execution/configuration
records, not unique methods. The nine-CA1416 CoreCLR compile failure and
three skipped dependent runtime stages remain a separate coverage gap:
available XML results do not certify the missing CoreCLR matrix.

The PR head, candidate base, and synthetic merge are unchanged.
Candidate protection remains `false`, the provisioning review gate
remains blocked, and zero-findings expert review is still not human
approval or runtime-gate success. No source changes, pushes, new queues,
review replies, or protection changes were made for this validation
update.

**Exact validation commands and results**

```sh
# Passed: Android-only repository build tasks.
dotnet build ./Microsoft.Maui.BuildTasks.slnf -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:BuildTaskOnlyBuild=true -v:q -nologo

# Passed for original, diagnostic control, fixed, reverted, restored, and immutable-head builds.
dotnet build src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj -c Release -f net11.0-android -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:RuntimeIdentifier=android-arm64 -p:EmbedAssembliesIntoApk=true -v:q -nologo

# Passed: original Android NUnit runner, with private transport only.
dotnet build src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -v:q -nologo

# Same command for each original-oracle phase; $resultdir selected a separate retained phase/attempt directory.
# Results are the actual cases in the phase table above; no automatic test retry was added.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE="$resultdir/appium.log" dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'Name=CollectionViewInfiniteScroll' --logger 'trx;LogFileName=original.trx' --results-directory "$resultdir" -v:q -nologo -- "NUnit.TestOutputXml=$resultdir/nunit"

# Passed: original 77-case selector, after pushing and verifying the exact immutable head.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/appium.log dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'TestCategory=CollectionView2' --logger 'trx;LogFileName=collectionview2.trx' --results-directory /Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2 -v:q -nologo -- NUnit.TestOutputXml=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/nunit

# Passed.
xmllint --noout src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml
# Passed.
git diff --check

# Not completed: bounded/stopped during full-solution loading without output; no formatting pass claimed.
# Only XAML changed; native XAML compilation and XML syntax checks above passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml --verify-no-changes --verbosity quiet
```

Direct source build/install/NUnit commands mirror the existing Cake
UI-test recipe and deliberately avoid the local wrapper's global ADB
restart/recovery behavior in this shared environment. Pre-existing
emulators and their ADB server were preserved.

### 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. -->

Relates to #40116, #39491, and #40227. These references are
intentionally non-closing; this corrects the incremental-loading
sample's scroll-mode contract.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
mattleibow added a commit that referenced this pull request Nov 24, 2026
Resolve the conflicts with main's net11 forward fixes (#40577):

- MauiRecyclerView.cs (Android): when the adapter is replaced, stop both
  main's _itemsUpdateScrollObserver (#39491) and the anchor's
  _scrollAnchorObserver. Adapt the anchor's DataChangeObserver to main's
  Action<bool> callback.
- ItemsViewController2.cs (iOS, Mac Catalyst): in ViewDidLayoutSubviews,
  keep main's InvalidateMeasureIfContentSizeChanged(afterLayout: true)
  (#39882) before the anchor's LayoutFinished. In UpdateItemsSource, keep
  main's CheckForEmptySource before the anchor's Reset, which stays just
  before the offset reset.
- PublicAPI.Unshipped.txt: keep both sides' entries. Both sides added
  ItemsViewController2.ViewDidLayoutSubviews, which is listed once.

While the view follows an edge, ItemsUpdatingScrollMode still doesn't
scroll it, now including main's KeepItemsInView scroll to the first item
(#39491, #39493). While it doesn't, ItemsUpdatingScrollMode applies as
usual, as AnchorMode documents.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
mattleibow added a commit that referenced this pull request Nov 24, 2026
Merging main (#40577) brought #39491 and #39493: KeepItemsInView, the
default ItemsUpdatingScrollMode, now scrolls a list to its first item
as items are added. While the list doesn't follow an edge, AnchorMode
leaves ItemsUpdatingScrollMode to apply as usual, so the tests that
check that only the anchor moves such a list failed with the list at
its first item: 7 cases on Android, and 1 on Mac Catalyst. They now set
KeepScrollOffset, and the AnchorMode remarks say what the default does.

The iOS and Mac Catalyst test helpers GetItemHeight and
GetGroupedItemHeight no longer dispose the index path they look up. It
is the managed peer of UIKit's equal index path, which the handler can
hold while a Scrolled handler calls them. After the merge, the layout an
animated ScrollToEnd forced raised Scrolled while ItemsViewController2
reconfigured the grown row: disposing the shared index path made
InvalidateItems throw NSInvalidArgumentException inside UIKit's layout,
and the Mac Catalyst device-test app crashed later in the run.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo kubaflo added this to the .NET 11 SR2 milestone Nov 24, 2026
kubaflo added a commit that referenced this pull request Nov 25, 2026
…ctionView enumeration (#40623)

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [X] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Root Cause

The KeepItemsInView fix in #39491 introduced
GetLayoutManager().ItemCount > 0 to avoid scrolling an empty collection.

However, obtaining ItemCount for a grouped source counts every group.
For enumerable-backed groups, this requires enumeration—even of groups
unrelated to the insertion.

Consequently, inserting into the first group unnecessarily enumerates
the last group, violating the assertion in
GroupedInsertWithoutScrollingAxisSpacingDoesNotCountAllGroups,
introduced by #40318.

The guard is redundant for this grouped path: the existing flat-index
resolver locates the first data item without counting all groups.

### Description of Change

Removes the `GetLayoutManager().ItemCount > 0` guard before the
`KeepItemsInView` first-item scroll request introduced in
#39491.

For grouped sources, obtaining the adapter count walks every group and
enumerates enumerable-backed groups. This adds unnecessary work when
inserting into the first group

The existing flat-index resolver already locates the first grouped data
item, skipping empty leading groups and stopping once the target is
found. A full adapter count is unnecessary.

Insertion-only handling, non-animated scrolling, and header/group
mapping remain unchanged. Removing the last ungrouped item does not
trigger this path, because removal notifications are not treated as
insertions.

### Issues Fixed
Related: #39491 and #40318.

**Test coverage**

The existing device test
`GroupedInsertWithoutScrollingAxisSpacingDoesNotCountAllGroups` covers
this regression with cross-axis spacing values of `0` and `8`.

No new test was added because this existing test directly covers the
unnecessary full-count enumeration addressed by this fix.

### Tested the behaviour in the following platforms
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac


### Output Screenshot
Before Issue Fix | After Issue Fix |
|----------|----------|
|<image width="100" height="200" alt="Before Fix video"
src="https://github.com/user-attachments/assets/361741a2-b54b-4b7c-a925-8a5bba16b945">|<image
width="100" height="200" alt="After Fix video"
src="https://github.com/user-attachments/assets/33bc9ae7-f631-4d88-a33f-0011a10f4b29">|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Nov 25, 2026
…View in view (#40211)

<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `0a18c2b26b92e131c5962f1686da929a504392f1`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 7.5/10 | ↑ Merged with `main` at dfca8ad37c, which
moves the repo to .NET 12 (#40060). Only the six Controls PublicAPI
files conflicted, resolved as the exact union of both sides.<br>↑ With
the pinned .NET 12 SDK: Controls.Core builds for net12.0, netstandard2.0
and netstandard2.1 with the PublicAPI analyzers, 0 warnings.
`Controls.Core.UnitTests`: 7033 pass, 30 skipped, including the 108
anchor tests.<br>↑ Each review fix was reproduced by a test that failed
before it.<br>↑ Before this merge, on .NET 11: Android API 37, 300
`CollectionViewTests` pass; Mac Catalyst (macOS 27.2.1), 209 pass.<br>↓
Not built or run locally on .NET 12 for Android, iOS or Mac Catalyst:
this machine has no .NET 12 workloads, and too little free disk to
install them.<br>↓ CI on this head is pending: maui-pr builds every
platform on .NET 12; uitests and devicetests need a maintainer's `/azp
run`.<br>↓ With `main`'s default `KeepItemsInView`, a list the user
scrolled away from jumps to its first item as items are added unless the
app sets `KeepScrollOffset`. |
<!-- /copilot-assessment -->

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

This is a new feature with new public API, so it targets `main`.

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

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

Chat, AI-streaming, log and feed screens need a list that keeps one edge
of its content in view while the content changes:
- **The end**, for chats and logs. This includes while the last item
grows in place as an answer streams in.
- **The start**, for feeds that add the newest items at the top.

The list must stop following when the user scrolls away to read, and
start again once they're back at that edge. CollectionView can't do this
today, so every app writes its own scroll tracking. The hard part of
that tracking is telling a user's scroll apart from the platform moving
the offset while rows re-measure.

`ItemsUpdatingScrollMode.KeepLastItemInView` doesn't cover it:
- it only reacts to collection changes;
- it scrolls even while the user reads history;
- it stops at the last item, short of a footer.

Blazor's `Virtualize` added the same capability in .NET 11 for the same
scenarios (`VirtualizeAnchorMode`, dotnet/aspnetcore#65742). This PR
builds the behavior of the dotnet/maui-labs prototype
(dotnet/maui-labs#842) into CollectionView itself, with the same modes
as Blazor.

#### API

```csharp
[Flags]
public enum ScrollAnchorMode
{
    None = 0,   // today's behavior, the default
    Start = 1,  // follow the start: feeds that add the newest items first
    End = 2,    // follow the end: chats, logs, feeds that append
}

public partial class StructuredItemsView
{
    public static readonly BindableProperty AnchorModeProperty;
    public ScrollAnchorMode AnchorMode { get; set; }

    public static readonly BindableProperty IsAnchoredProperty;
    public bool IsAnchored { get; }                   // read-only: whether the view follows an edge right now

    public void ScrollToStart(bool animate = true);   // to the start of the content, header included
    public void ScrollToEnd(bool animate = true);     // to the end of the content, footer included
}
```

The handlers gain `MapAnchorMode` (`CollectionViewHandler2` on iOS and
Mac Catalyst, `StructuredItemsViewHandler<TItemsView>` on Android).
These overrides also show up in `PublicAPI.Unshipped.txt`, because the
anchor listens to the platform's own callbacks:
- `MauiRecyclerView.OnScrolled` and `OnScrollStateChanged`
- `ItemsViewController2.ViewDidLayoutSubviews`
- `ItemsViewDelegator2.DraggingStarted`, `DraggingEnded` and
`DecelerationEnded`

```xml
<CollectionView x:Name="messages" AnchorMode="End" ItemsSource="{Binding Messages}" />
<Button Text="Jump to latest" Clicked="OnJumpToLatest"
        IsVisible="{Binding IsAnchored, Source={x:Reference messages}, Converter={StaticResource InvertedBool}}" />
```

```csharp
void OnJumpToLatest(object sender, EventArgs e) => messages.ScrollToEnd();
```

#### Compared with Blazor's `Virtualize.AnchorMode`

| | Blazor `Virtualize` | `CollectionView` |
| --- | --- | --- |
| Modes | `None`, `Start`, `End`, as flags | the same names and values |
| Default | `Start` | `None`, which keeps today's behavior |
| `Start \| End` | pins both edges; the end wins when the list is at
both | follows whichever edge the view is at, and the end when it's at
both |
| Detecting prepends | `ItemComparer` for `ItemsProvider` sources | not
needed: the anchor measures the content's offset and extent, not items |
| Whether it follows now | not exposed | `IsAnchored`, bindable |
| Back to an edge | the app scrolls the container | `ScrollToStart` and
`ScrollToEnd`, which reach past the header and footer and follow that
edge again |
| Near-edge threshold | 2 px | 8 device-independent units |

#### Behavior

- **`End`:**
  - The view shows the end of its content when it first appears.
  - It keeps the end in view while:
    - items are added or removed;
    - any item grows or shrinks, the last one included;
    - the header or footer changes, in grouped lists too;
    - the viewport resizes.

"The end" means the end of the content, footer included, not the last
item. Following never animates.
- **`Start`** does the same for the start of the content, above the
header. Items inserted before the first item while the view is at its
start come into view instead of landing above it.
- **`Start | End`:**
  - The view starts at the end and follows whichever edge it's at.
  - When it's at both, because its content fits, it follows the end.
- **Changing modes:** Changing `AnchorMode` starts over, as when the
view first appears. Replacing `ItemsSource` or changing `IsGrouped` does
too.
- **Scrolling away:** A user scroll more than 8 device-independent units
away from the edge stops following, and `IsAnchored` becomes `false`. So
does a scroll the user isn't making, such as one from the keyboard,
accessibility, a status-bar tap, or code moving the native view, also
right as a fling or an animated scroll ends. On iOS and Mac Catalyst
17+, a scroll UIKit animates, such as a status-bar tap or code animating
the native view, counts as a fling until it ends, as a smooth scroll
does on Android. None of these stop it:
  - content growing during the gesture;
  - a bounce;
- offset changes the platform makes while laying out, even when the
content ends up the size it started.
- **Scroll requests:**
- A `ScrollTo` from the app is judged by where it lands. Animated, it
carries on as the content changes on the way, and doesn't take the view
back to the edge it left.
  - The latest request wins:
- a `ScrollTo` right after `ScrollToEnd` isn't undone by following the
end;
- a `ScrollTo`, or a change of `AnchorMode`, made from the `Scrolled`
event or the `IsAnchored` change that `ScrollToStart` or `ScrollToEnd`
raises wins over them, also when it turns anchoring off, and so does a
`ScrollTo` from the `Scrolled` event that replacing `ItemsSource`
raises;
- a `ScrollToStart` or `ScrollToEnd` made from the `Scrolled` event that
a `ScrollTo` raises, or from the `RemainingItemsThresholdReached` that a
`ScrollTo` raises as it stops a scroll, wins over that `ScrollTo`;
- a `ScrollToEnd` or `ScrollToStart`, or a change of `AnchorMode` to
`Start` or `End`, right after an animated `ScrollTo` stops that
animation;
- an animated `ScrollToStart` or `ScrollToEnd` right after one to the
other edge that doesn't animate goes to its own edge;
- an animated `ScrollTo` right after a `ScrollToStart`, `ScrollToEnd` or
`ScrollTo` that doesn't animate goes to its item;
- a `ScrollTo` for an index the items don't have, before the first or
past the last, leaves what an earlier scroll is still finishing as it
is.
  - A `ScrollTo` that finds nothing to scroll to changes nothing.
- Reaching the edge again, however the view gets there, starts following
again.
- **`ScrollToStart` and `ScrollToEnd`:**
- They scroll above the header or past the footer, which `ScrollTo(0)`
and `ScrollTo(lastIndex, position: End)` can't reach.
- With the matching mode, the view follows that edge from the moment
it's asked to. "Jump to latest" never sees `IsAnchored` flash `false` on
the way, also while the platform measures the rows an animated one
brings into view. A scroll the user isn't making that stops an animated
one on its way, such as code moving the native view or a status-bar tap,
leaves the view where it stopped, judged as any other scroll. An
animated one to the edge the view is at already doesn't animate, and a
scroll away right after it is judged as any other.
- Without it, they scroll there once. They go the rest of the way once
the rows they brought into view are measured. Animated, they carry on as
the content changes on the way, such as an answer streaming in, and
don't take the view back to the edge it left. A scroll that stops an
animated `ScrollToStart` on its way, such as code moving the native
view, leaves the view where it took it.
  - Like `ScrollTo`, they do nothing before the view has a handler.
- **Turning anchoring off:** Setting `AnchorMode` to `None` stops
following at once, even from a `Scrolled` handler that the anchor's own
correction raised. It isn't a scroll: the view stays where it is, and a
scroll under way, such as an animated `ScrollTo`, carries on. An
animated `ScrollToStart` or `ScrollToEnd` to the edge the view followed
still goes all the way there, as it does without the mode.
- **`ItemsUpdatingScrollMode`:** While the view follows an edge,
`ItemsUpdatingScrollMode` doesn't scroll it. Otherwise that mode applies
as usual, and this PR doesn't change any mode. On `main`,
`KeepItemsInView`, the default, now scrolls the view to its first item
as items are added (#39491, #39493), also a view the user scrolled away
from an edge; `KeepScrollOffset` leaves it where the user scrolled. The
`AnchorMode` remarks say so.

#### How it works

- An internal, platform-agnostic `ScrollAnchorTracker` makes every
decision, following one edge at a time. Its inputs are the offset,
content extent and viewport that the platform reports after each layout
and scroll. Measuring the content extent, rather than tracking items, is
what makes groups, headers, footers and growing items work. The unit
tests spell out its rules.
- The platform code only reads native metrics and scrolls. It uses the
handlers' own signals, with no extra gesture recognizers or external
listeners:
  - **iOS and Mac Catalyst (Items2):**
- Layout: `ItemsViewController2.ViewWillLayoutSubviews` and
`ViewDidLayoutSubviews`. UIKit also lays the view out when the
controller sets a new layout (a header or footer replaced) and when the
items source applies items added, removed or moved. It can move the
offset there before it updates the content size, so the controller
brackets those updates as layout too.
- Scrolling: the `Scrolled`, `DraggingEnded` and `DecelerationEnded`
callbacks on `ItemsViewDelegator2`. A scroll the user isn't making is
judged straight away in `Scrolled`, before the layout pass that measures
the rows it brings into view. It's judged as a new scroll, also right
after a drag, a deceleration or an animated scroll ended, before the
layout pass that looks at where that one stopped. If the content or the
viewport changed size since the anchor last looked, the offset moved for
that change, as when the keyboard manager sets the view's insets, and
it's judged as layout.
- One-shot scrolls: a `ScrollToEnd` without End anchoring finishes in
the layout passes after it, because UIKit estimates rows at 30 points
until it measures them. It finishes only in a layout pass UIKit runs on
its own: one it forces right after the scroll may not have measured the
rows there yet.
- An animated `ScrollToStart` or `ScrollToEnd` to an edge the view
doesn't follow counts as a fling until UIKit reports that its animation
ended, the user drags, or the app requests another scroll, as a
requested smooth scroll does on Android. The anchor used to judge it in
the layout right after the request, before the animation moved the view.
So it followed the edge the view was leaving again, and a row measured,
grown or added before the view got clear of that edge scrolled it back
there, which stopped the animation. UIKit doesn't animate a view that
isn't in a window: it scrolls the view there and reports that the
animation ended before the call returns. The controller counts those
reports, so such a request is done at once, and `ScrollToEnd` goes the
rest of the way as from the end as laid out.
- UIKit keeps the rows in view in place as it measures the rows an
animated scroll to the start brings into view above them, so the
animation stops short of the start by as much as those rows grew. A
one-shot `ScrollToStart` goes the rest of the way once the animation
ends, unless the view stopped further from the start than the content
grew meanwhile, plus 8 units. A scroll stopped the animation then, such
as code moving the native view, and the view stays where that scroll
took it. It used to jump to the start whenever the animation ended.
- A scroll UIKit animates that the anchor didn't start, such as code
animating the native view or a status-bar tap, counts as a fling while
`ScrollAnimating` says it animates (iOS and Mac Catalyst 17+), and the
anchor looks again once UIKit reports its end. It used to be judged as a
scroll the user isn't making: within 8 units of the edge it was leaving,
the view still followed that edge, and a row UIKit measured, or the
content growing, as the animation started took it back there, which
stopped the animation. Before iOS 17 it's judged as before.
- An animated `ScrollTo` counts as a fling the same way while UIKit
animates it. UIKit doesn't animate a scroll to where the item already
is, and never reports an end for it, so the controller checks
`UIScrollView.ScrollAnimating` (iOS and Mac Catalyst 17+) once the
request returns. The anchor used to judge the request in the first
layout, before the animation moved the view: from the end of a list that
follows its end, it kept following the end, and the content changing
then scrolled the view back there, which stopped the animation. Before
iOS 17, which doesn't tell (Mac Catalyst's minimum is 17), it's judged
in the first layout, as before: a content change between that layout and
the animation's first frame still takes the view back to the end there.
- An animated `ScrollToStart` or `ScrollToEnd` to the edge the view
follows keeps following that edge until it gets there. UIKit reports
when its animation ends. An end short of where the animation was going
was a scroll stopping it, such as code moving the native view or a
status-bar tap, unless the anchor's own correction stopped it, UIKit
stopped it while laying the view out, or the content or the viewport
changed size. The anchor then judges where the view stopped. It used to
keep following the edge, so `IsAnchored` stayed `true` and the next
content change pulled the view to the edge. A drag or a newer request
forgets the animation, so the stop that `ScrollToStart` and
`ScrollToEnd` make before they scroll isn't judged.
- An animated `ScrollToStart` or `ScrollToEnd` to the edge the view
follows and is at already doesn't animate, and UIKit reports no end for
it. It now jumps there, as one that doesn't animate does, which judges
where the view is at once. It used to follow the edge as for an
animation on its way there: a scroll away right after it was ignored,
and the rows that scroll brought into view pulled the view back to the
edge.
- A grouped list that measures all its items scrolls to the item again
once an animated `ScrollTo` ends, as on `main`. It now waits for that
end only when UIKit reports one: on iOS and Mac Catalyst 17+ when
`ScrollAnimating` says the scroll animates, and before 17 when the view
is in a window. Otherwise it scrolls again at once. A view that isn't in
a window doesn't animate, and UIKit reports the end before the scroll
returns, so the callback registered after the scroll ran at the end of a
later, unrelated animation, which scrolled back to the item. UIKit never
reports an end for a scroll to where the item already is, either.
- Requests are numbered by the controller. A `ScrollTo`, `ScrollToStart`
or `ScrollToEnd` that a newer request or mode change superseded from its
own `Scrolled` event stops there, also from the layout `ScrollToStart`
and `ScrollToEnd` force before they scroll, and a superseded `ScrollTo`
doesn't arm Mac Catalyst's restore (#34271).
- UIKit records a `scrollToItem` target and applies it again in later
self-sizing layout passes, unless the view really scrolled after
`scrollToItem` returned. So a `ScrollToStart` or `ScrollToEnd` requested
while `ScrollTo` is inside `scrollToItem` runs once it returns.
- Mac Catalyst can move the offset without telling the scroll view
delegate or laying the view out (#34271, #36431). The anchor hears of
that through the `contentOffset` KVO observer `MauiCollectionView`
already has, counts the move as the platform's, and follows its edge
again, replacing the restore of a `ScrollTo` that anchoring clears. The
anchor clears that restore whenever it reports that the view follows an
edge, also when the view got back to it without a drag, as the keyboard
or accessibility scroll it: the restore would otherwise take the view
back to the item when the anchor moves it up as the content shrinks. The
observer tells the controller directly, through a listener it holds
weakly rather than an event, so it doesn't allocate on every scroll
tick.
- While anchored, `LayoutFactory2.FinalizeCollectionViewUpdates` returns
early.
- A mode change stops an animated scroll the app requested, as the view
goes to the edge it now follows. A horizontal layout isn't anchored, so
there a mode change leaves the scroll, the grouped scroll's callback and
Mac Catalyst's restore alone.
- Turning anchoring off while an animated `ScrollToStart` or
`ScrollToEnd` is still on its way to the edge the view followed hands
that scroll to the step that finishes a one-shot scroll once its
animation ends, unless the app requested a newer scroll. Without it, the
scroll stopped where its animation ended, short of an edge that rows
measured on the way had moved.
  - **Android:**
- Signals: `MauiRecyclerView.OnLayout`, `OnScrolled` and
`OnScrollStateChanged`, plus an adapter data observer like the ones
`EmptyView` and `ItemsUpdatingScrollMode` use. RecyclerView keeps the
first row it shows in place as it applies item changes, so the offset
moves even when the content stays the same size. The look after the
layout that applies them counts that move as the layout's. While
anchored, `AdjustScrollForItemUpdate` returns early. The look at a view
whose scroll went idle is posted to the next frame: a scroll reported
before it is judged as a new one, not as the end of the gesture.
- Measuring: RecyclerView's `computeVerticalScrollOffset` and
`computeVerticalScrollRange` are estimates based on the average row
size, so the anchor measures from the laid-out rows instead. The offset
follows a reference row, identified by its view *and* its adapter
position, because RecyclerView reuses a row's view for another row even
within one frame of a fast scroll. Without the first row laid out, the
offset comes from rows laid out before, or from the estimate, which can
be far off with rows of very different heights. A row above the view can
also change size while it isn't laid out: an item replaced, or resized
by a binding, which nothing reports until the row is laid out again. So
the view isn't taken to be at the start until the first row is laid out.
When the first row is laid out again after the offset came from the
estimate, the view moved only as far as the row it kept in view, or the
scroll, says: the anchor tells the tracker that the rest is a new origin
(`ScrollAnchorTracker.MoveOrigin`), not movement. A single scroll away
from the end, by code moving the native view, that first laid out a
first row much taller than the others used to look like a move toward
the end, and the list was pulled back there.
- `ScrollTo` from inside a layout: RecyclerView raises `Scrolled` as it
lays out, and Android drops a layout that a view requests during its own
layout. So a jump requested from there used to land only at some later,
unrelated layout. `ScrollHelper` now requests the layout again once the
current one is over. The adjustment the jump leaves (centering or ending
an item, or reaching the end of a last row taller than the view) waits
for that layout too, instead of running at the end of the current one,
before the jump has scrolled. The anchor judges that request in the
layout that lands it. A correction the anchor has to post the same way,
because the row at the edge isn't laid out yet, leaves the tracker
measuring from where the view was
(`ScrollAnchorTracker.DeferCorrection`), as a scroll can move the view
first: the next look judges that scroll, which stops following the edge
if it took the view away, and otherwise asks for the correction again.
- `ScrollTo(index, groupIndex)` now computes the adapter position from
the group sizes, as the flat index already did. It used to look the item
up one position on (right only for groups with a header) and then search
for an equal item, so it skipped an item, or threw, in groups without a
header, and could land on an equal item in an earlier group. Device
tests call it for a group without a header and for an item equal to one
in an earlier group.
- A `ScrollTo` that doesn't animate, for an index the items don't have
(past the last item, or the header's or footer's position), no longer
replaces a scroll requested before it that hasn't been laid out yet, as
iOS ignores such indices. Animated, it still scrolls there, or to the
last item for an index past it.
- Turning anchoring off while the anchor reports `IsAnchored` stops an
animated scroll to an edge it was about to start. `ScrollToStart` and
`ScrollToEnd` drop a `MandatorySingle` fling's snap target, as
`ScrollTo` does, so the snap doesn't take the view back to it.
- A mode change or a new `ItemsSource` stops an animated scroll the app
requested, all the way to where it ends, as the view goes to the edge it
now follows. RecyclerView's smooth scroller stops once it finds its
target and leaves the rest of the scroll to RecyclerView, which settles
it as it settles a fling, so `IsSmoothScrolling` is `false` for that
last stretch. `MauiRecyclerView` remembers that the scroll is the app's
until the view stops or the user drags it. A fling of the user's still
carries on. On a horizontal layout, which isn't anchored, a mode change
doesn't stop the scroll, and isn't a newer scroll request: a `ScrollTo`
that doesn't animate still jumps to its item when the app changes the
mode from the `RemainingItemsThresholdReached` it raises as it stops a
scroll.
- A new `ItemsLayout` that scrolls vertically after one that didn't
starts the anchor over as `MauiRecyclerView` replaces the layout
manager, as a new view does, rather than at the first look after the
next layout. A `ScrollTo` the app requests right after it, in the same
update, is judged by where it lands, as on iOS and Mac Catalyst, where
the controller looks while it swaps the layout. One requested right
before it was for the layout manager it replaced, and gives way to the
new layout.
- Stopping a scroll raises a pending `RemainingItemsThresholdReached` as
RecyclerView goes idle. A scroll the app requests from it is newer than
the request that stopped the view, so the view doesn't go where that
request was going after it: a mode change, or a `ScrollToStart`,
`ScrollToEnd` or `ScrollTo` that doesn't animate. `ScrollToStart`,
`ScrollToEnd` and a `ScrollTo` that doesn't animate stop the view
themselves before they jump, with or without a matching anchor, because
RecyclerView's `scrollToPosition` would stop it first and then set the
older position.
- An animated `ScrollToStart` or `ScrollToEnd`, with anchoring or
without it, starts once the view is laid out, as iOS lays the view out
before it scrolls. So does one on a horizontal layout, which goes to the
first or last item. RecyclerView's smooth scroller works out how far to
go in the next frame's animation, which comes before that frame's
layout. So a row the app grew with the request moved the end after the
scroll had stopped, and nothing followed it. And a jump to the other
edge that an earlier request left for that layout landed after the
smooth scroller had already stopped, having found its target in place.
The request waits where `ScrollHelper` keeps a jump's adjustment, so a
newer request replaces it. A mode change to `Start` or `End` cancels it,
and the adjustment a jump left, as it stops an animated scroll the app
requested.
- An animated `ScrollTo` whose item is already in place doesn't scroll:
the smooth scroller stops in its first step, and nothing reports that.
The anchor judged the request only at the next content change, after the
change had moved the content, and stopped following the edge the view
was at. It now looks once the smooth scroller has taken its first step,
which judges such a request where the view is, and one that scrolls as a
fling.
- An animated `ScrollTo` for an item starts once the view is laid out
while a jump hasn't been made yet: one from `ScrollToStart`,
`ScrollToEnd` or a `ScrollTo` that doesn't animate, or the anchor's jump
to its edge. RecyclerView makes the jump in the next layout, and the
smooth scroller's first step comes before it: finding the item the view
showed in place, it stopped, and the jump then took the view away.
`ScrollHelper` and the anchor record a jump until that layout. A
`ScrollTo` past the last item, as `KeepLastItemInView` requests, starts
at once as before.
- `ScrollToStart` and `ScrollToEnd` reach the platform through an
internal `IScrollToEdgeHandler`. Where the view can't scroll to an edge
of its content, the handler scrolls to the first or last item it shows,
grouped or not. It finds that item in its own items (the adapter, the
collection view's sections, or WinUI's `CollectionViewSource`), not by
reading `ItemsSource` again, so a sequence that can be read only once
and groups that aren't lists work. Only handlers without the interface
(the obsolete iOS handler, the opt-out Windows `CollectionViewHandler`,
custom handlers) fall back to `ScrollTo` the first or last item
`ItemsSource` gives.

| Platform | `AnchorMode` `Start` and `End` | `ScrollToStart` and
`ScrollToEnd` |
| --- | --- | --- |
| iOS, Mac Catalyst (Items2, the default handler) | vertical layouts |
edges of the content |
| Android | vertical layouts | edges of the content |
| Windows (Items2, the default handler) | not implemented, `IsAnchored`
stays `false` | first and last item (unverified) |
| iOS legacy handler (opt-in) | not implemented | first and last item |
| Horizontal layouts | not anchored | first and last item |

#### Tests

- **Unit tests** (`Controls.Core.UnitTests`): 108/108 pass on .NET 12,
after merging `main` at dfca8ad37c. The whole project passes too: 7033
tests, 30 skipped.
  - 83 tracker tests spell out the rules for both edges.
  - 25 cover the API:
    - `AnchorMode` and `IsAnchored`;
    - how `ScrollToStart` and `ScrollToEnd` reach the handler;
- their `ScrollTo` fallback, grouped lists, and calls without a handler,
which don't read `ItemsSource`.
- **Device tests** (`CollectionViewTests.ScrollAnchor.cs`): 145 cases
run on Android, 142 on iOS and 144 on Mac Catalyst, as some are
platform-specific. They last ran locally on .NET 11, before the merge of
`main` at dfca8ad37c moved the branch to .NET 12; CI runs them on .NET
12. Each review fix was first reproduced without the fix, by a device
test, a unit test, or a scripted check on Mac Catalyst. In the latest
rounds, on the Android emulator unless noted:
- A new test of 2 cases turns a horizontal `End` list vertical and
requests `ScrollTo(10)` right after it, or right before it, in the same
update. Before the change, the case with the request after the switch
failed on Android: item 10 never came into view, as the anchor started
over at its first look after the layout and dropped the request. Both
cases pass on Android and Mac Catalyst.
- Merging `main` (#40577): with #39491 and #39493, `KeepItemsInView`,
the default `ItemsUpdatingScrollMode`, scrolls a list that doesn't
follow an edge to its first item as items are added. 5 tests (9 cases)
check that only the anchor moves such a list, and 8 of those cases
failed with the list at its first item: 7 on Android, and 1 of the 2 Mac
Catalyst cases of another, whose other case passed only because the list
went to its start, away from its end. The 5 tests now set
`KeepScrollOffset`, and pass.
- After the merge, the Mac Catalyst device-test app crashed 3 times in 3
runs (SIGBUS and SIGSEGV in UIKit's observation tracking, during
layout). The first managed failure was an `NSInvalidArgumentException`
("attempt to insert nil object") from `InvalidateItems` in
`ItemsViewController2.InvalidateLayoutIfItemsMeasureChanged`, inside the
layout an animated `ScrollToEnd` forced. The test helpers
`GetItemHeight` and `GetGroupedItemHeight`, called from a `Scrolled`
handler in that layout, disposed the index path they looked up: the
managed peer of UIKit's equal index path, which the handler held for
`InvalidateItems`. They no longer dispose it; the class then passes. The
pre-merge head passed on the same machine (macOS 27.2.1), so the merged
layout timing exposed it.
- On Android, a new test opens an `End` list whose first row is 1000
high and whose other 110 rows are 3 high, so at the end the first row
sits just above the view, measured only by RecyclerView's estimate. Code
then scrolls the native view up 100, which lays that row out. Before the
change, the list was pulled back to its end: the first row at -2455 px
right after the scroll, then row 12 at the top. Two new tracker tests (3
cases) cover `MoveOrigin`; all 3 fail with it doing nothing.
- On Android, a new test of 2 cases (`None`, `Start`) has a
`ScrollTo(5)` that doesn't animate stop an animated scroll on a
horizontal list, and the app changes `AnchorMode` to `End` from the
`RemainingItemsThresholdReached` that stopping raises. Before the
change, both failed: the mode change dropped the jump, and item 5 never
came into view.
- On iOS and Mac Catalyst, a new test of 2 cases calls an animated
`ScrollToStart` or `ScrollToEnd` on a list at that edge, and then has
code scroll the native view 200 away from it. Before the change, both
failed on Mac Catalyst, with the list pulled back to the edge.
- On iOS and Mac Catalyst, a new test of 4 cases (`None` or `End`, the
scroll animated or not) has code scroll the native view to 100 short of
the end right after an animated `ScrollToStart` from the end. Before the
change, both animated cases failed on Mac Catalyst: the jump to the
start overrode that scroll, and the list never got to 100 short of its
end. The others passed before too: UIKit reports the end of an animation
that a scroll without animating stops before it applies that scroll. The
test allows for UIKit moving the end further away as it measures the
rows the scroll brought into view, which once left the list 230 short of
the end, with the offset where the scroll put it.
- That test's animated `End` case also failed in 5 or 6 of 10 repeats,
for a race this round fixes: a row UIKit measured while the view was
still within 8 units of the end took the view back there. A new test
grows the last row as code starts animating the native view of an `End`
list 100 short of the end. Before the change, the list was back at the
end and still anchored in each of 3 tries on Mac Catalyst. Now it ends
where a list without anchoring does: 130 short of the end on macOS 27,
as UIKit measures the rows above again. All 10 repeats of the race pass.
CI's Mac Catalyst run on macOS 26 ended that test 360 short of the end,
where it had checked for at most 300: UIKit there measures the rows
above differently, and iOS 26 and macOS 15 passed it. The anchor only
ever scrolls a list that follows its end to the end, so the test now
checks that the list stays away from both edges (less than half the
scroll range from the end) rather than how far UIKit takes the end.
- The test of a `ScrollToEnd` from `Scrolled` as `ScrollToStart` goes
the rest of the way used to fake UIKit's report that the animation
ended, right after the request, with the list still at the end. It now
lets UIKit stop the animation short of the start: 200 short on Mac
Catalyst, as rows are estimated at 30 and measure 40.
- A new Android test of 4 cases (`ScrollToStart` or `ScrollToEnd`, with
a matching anchor or none) stops an animated scroll past the
`RemainingItemsThresholdReached` threshold with a `ScrollTo(20)` that
doesn't animate, and calls `ScrollToStart` or `ScrollToEnd` from that
event. Before the change, both cases without an anchor failed: the older
`ScrollTo` won, with row 13 at the top, or the end out of view. With a
matching anchor they passed before too, as the anchor's reset takes the
view to its edge.
- On iOS and Mac Catalyst, a new test of 2 cases stops an animated
`ScrollToEnd` on its way with a native scroll back to the start, without
animating, or animated as a status-bar tap does. Before the change, both
failed on the iPhone 18 Pro simulator: the list stayed at its start, but
`IsAnchored` stayed `true`.
- On iOS and Mac Catalyst, a new test of 2 cases (`End`, `MakeVisible`)
makes an animated `ScrollTo` in a grouped list that measures all its
items while the list is out of its window, and then scrolls the native
view back toward the start, animated. Before the change, both failed on
the iPhone 18 Pro simulator: as that animation ended, the list scrolled
back to the item, 1006 from the start (878 when it first showed the
item). UIKit stops that animation short of the start, as it measures the
rows above that the jump skipped, so the test checks that the list
doesn't go back to the item rather than that it reaches the start.
- A new test of 2 cases calls `ScrollToEnd(false)` and then an animated
`ScrollToStart` on a horizontal list at its start, and the reverse.
Before the change, both failed on Android, with the list at the edge it
jumped to. iOS and Mac Catalyst passed before the change too.
- A new test of 4 cases (every `AnchorMode`) calls `ScrollToEnd(false)`
and then an animated `ScrollTo(0)` on a list at its start. Before the
change, all 4 failed on Android with the list at the end (row 32 at the
top), including End and Start | End, where the jump was the anchor's.
iOS and Mac Catalyst passed before the change too.
- On iOS and Mac Catalyst, a new test insets the bottom of an End list
by 300 and scrolls the native view up 200 outside a layout pass, as the
keyboard manager does. The anchor judges that as layout and keeps the
end in view. With the `IsResized` veto removed, it failed on the iPhone
18 Pro simulator: 530 from the end, no longer following it.
- On iOS and Mac Catalyst, a new test has code scroll the native view up
200 right after UIKit reports that an animated scroll ended, before the
layout pass that follows. UIKit reports the end of a drag, a
deceleration or an animated scroll before that pass, and the anchor took
a scroll in between for the end of the one that ended. Before the
change, the list was pulled back to its end on the iPhone 18 Pro
simulator, 0 from the end. A new tracker test covers `IsResized`: an
offset move that comes with a size change is still judged as layout.
- On Mac Catalyst, back at the end of an End list after a `ScrollTo(0)`
that doesn't animate, through native scrolls that aren't drags, a new
test shrinks the last item. Before the change, the restore that
`ScrollTo` armed took the list back to its first item: 30 from the
start, 1100 from the end, not anchored.
- A native scroll up 200 from a scroll listener as a short fling goes
idle, before the anchor's posted look, has a new test. Before the
change, the list was pulled back to its end. Two new tracker tests cover
it: the original code took the view back to the edge, and gating the
gesture-end exemption alone stopped following for a scroll toward the
end.
- Code scrolling the native view up 200 from the GlobalLayout callback
after items are appended, before the anchor's posted jump to the new end
lands, has a new test. Before the change, the list jumped from row 27,
where the scroll left it, to the end at row 52. It passes now, and with
`DeferCorrection` resetting the tracker as before, the 2 new tracker
tests of a scroll away fail.
- An animated `ScrollTo` to the first item, from the end of a list that
follows only its end, has a new test of 2 cases: the last row grows, or
an item is added, once the list is laid out for the request and before
the animation moves it. Before the change, both failed with the list
back at the end: 1040 and 1120 from the start on the iPhone 18 Pro
simulator, 1170 and 1200 on Mac Catalyst. Android needed no change for
them. A new test of an animated `ScrollTo` to where the last item
already is failed on Android before the change: once the last row grew,
the list had stopped following, 80 short of the end. All 3 cases pass on
Android, iOS and Mac Catalyst now.
- CI's Mac Catalyst run on macOS 26 left an animated `ScrollToStart`
from the end of a list that follows only its end at the end, 1220 from
the start, in one of its two runs. A new test of 2 cases grows the last
row, or adds an item, once the list is laid out for the request and
before the animation moves it. Before the change, both failed on the
iPhone 18 Pro simulator and on Mac Catalyst, with the list back at the
end: 1220 from the start for the grown row on Mac Catalyst, as in CI.
Both pass on Android, iOS and Mac Catalyst now. Android needed no
change.
- A throwaway probe on the iPhone 18 Pro simulator showed that UIKit
reports the end of a scroll animation in every case it tried: one that
finishes, one a scroll stops, the view leaving its window, an inset,
content size or visibility change. A view that isn't in a window doesn't
animate: UIKit scrolls it and reports the end before the call returns. A
new iOS and Mac Catalyst test of 2 cases takes the list out of its
window for an animated `ScrollToStart` or `ScrollToEnd`. Before the
change, the `ScrollToStart` case failed on the iPhone 18 Pro simulator:
back at its end, the list didn't follow a new item, 40 short of the end.
Both pass on iOS and Mac Catalyst now.
- An animated `ScrollToStart` or `ScrollToEnd` right after one to the
other edge that doesn't animate, on a list settled at the edge the
animated one goes to, has a new test of 16 cases: every `AnchorMode`,
both edges, and with or without a header and footer. Before the change,
6 failed. The animated `ScrollToStart` that the view doesn't follow
(`AnchorMode` `None` or `End`) left the list at the end. With rows of
one height and no header or footer, an anchored `ScrollToStart` or
`ScrollToEnd` left it at the other edge too. All 16 pass on Android, iOS
and Mac Catalyst now.
- With the data-item check removed, a `ScrollTo` that doesn't animate,
for the footer's index (`items.Count`) or the header's (-1), right after
`ScrollToEnd(false)` cancelled the adjustment that finishes it: the list
stopped 299.8 and 350.1 short of the end.
- iPhone 18 Pro simulator: without the handover, turning `AnchorMode`
off during an animated `ScrollToEnd` or `ScrollToStart` to the edge the
list followed left it 230 short of the end and 130 from the start.
Android reached the edge either way.
- The check that scrolling the native view away as an item is added
stops following the end now runs on iOS and Mac Catalyst too. It passes
there unchanged: UIKit resizes the content as the item is inserted,
which the anchor looks at before the scroll.
- With the request check across the stop removed, a `ScrollTo` requested
from the `RemainingItemsThresholdReached` that stopping a scroll raises
lost to the edge the list went to: for a mode change, and for
`ScrollToEnd` and `ScrollToStart` that don't animate. Without stopping
the view before the jump, all four `ScrollToEnd` and `ScrollToStart`
cases failed, with a matching anchor and without one.
- With the horizontal check removed, both cases of the new test of a
mode change during an animated `ScrollTo` on a horizontal list failed.
On Android the scroll stopped and never reached the item. On the iPhone
18 Pro simulator it stopped too, and UIKit then put the view at the item
in a single jump at the next layout, so the test also checks that the
scroll keeps animating.
- Without the change to the animated `ScrollToEnd`, both cases of its
new test failed, with the last row grown before the request or after it:
the footer stayed out of view.
- CI's Mac Catalyst run on macOS 26 ended the case that grows the row
after the request 50 short of the end, in one of its two runs. iOS and
Mac Catalyst lay the view out as `ScrollToEnd` is called, and follow a
row grown after it only while UIKit measures the rows the scroll brought
into view (see open question 11), so that case runs on Android only.
Both cases check that the view reached the end of the grown row, as the
test of a row measured in a later layout does.
- With `main`'s lookup for `ScrollTo(index, groupIndex)` restored, both
of the new direct calls failed: one threw `ArgumentOutOfRangeException`
for a group without a header, and the other scrolled to the equal item
of the first group.
- With the anchor's stop left as it was, the case of a mode change right
after an animated `ScrollToEnd` failed: the scroll waiting for the
layout still took the list to the end.
- Android API 37 emulator, after merging `main` at bca4740888 (.NET 11):
all 300 `CollectionViewTests` pass, with 1 skip that predates this PR.
- Mac Catalyst (macOS 27.2.1), after merging `main` at bca4740888 (.NET
11): all 209 `CollectionViewTests` pass, with 4 skips that predate this
PR. The latest local iOS run (iOS 27.2) is of an earlier head: all 170
passed. CI's iOS stages, on macOS 15 and macOS 26 hosts, passed every
anchor test on 42c1a3060d. Each has 4 skips that predate this PR. The
Xcode 27.2 SDK requires a scene manifest in the device-test app
(MT7199), so these ran with one added locally. It isn't part of this PR.
- The horizontal cases wait until the list is laid out before they
scroll: before that, a list is at both of its edges, and they passed on
iOS without scrolling.
- CI's device tests on iOS 26 and macOS 26 found failures that iOS 27
and macOS 27 don't show. This head addresses them:
- UIKit moved the offset before it updated the content size, while it
updated the view for a new layout (a replaced header or footer) or for
removed items. The controller now brackets those updates as layout.
- Rows measured during an animated `ScrollToStart` moved the offset away
from the start before any size change was reported. An animated scroll
to an edge now follows that edge until it gets there.
- A one-shot `ScrollToEnd` that doesn't animate finished in the layout
passes it forced, before UIKit measured the rows there. It now finishes
only in a layout pass UIKit runs on its own.

The replaced header and the one-shot `ScrollToEnd` failed locally too,
and pass now. New unit tests cover following an edge on the way there,
and a new device test covers the one-shot `ScrollToEnd`. Only CI can
confirm the fixes on iOS 26 and macOS 26.
- **UI tests** (`CollectionViewAnchorModeEnd`, 3 tests). They cover
following added and growing items, scrolling away and back, and
`ScrollTo` away from the end followed by `ScrollToEnd`. The growing-item
test waits until the last message has grown before it checks that the
footer is in view. Their waits find a row again when the list recycled
it between finding it and reading its geometry.
  - 3/3 on an iPhone 18 Pro simulator (iOS 27.2) with real touch.
  - 3/3 on an Android API 37 emulator.
- **Mac Catalyst and the iPhone 18 Pro simulator:** local scripted
checks of the scenarios above all pass. They include:
  - 32/32 repeated one-shot `ScrollToEnd` runs on each;
- a `ScrollTo` from `Scrolled` or from `IsAnchored` during
`ScrollToEnd`, or from `Scrolled` as `ItemsSource` is replaced;
- a mode change during an animated `ScrollTo`, including before its
first frame;
  - `KeepLastItemInView` with `Start`;
- the restore armed by a `ScrollTo` that doesn't animate. With the two
clears removed, the list goes back to that item.
- **Not run locally:**
- Catalyst UI tests: on this machine Appium loses the app at launch for
any test page, including existing ones.
  - iOS 26 and macOS 26, which only CI has.

<details>
<summary>Commands</summary>

```bash
# Unit tests: 108 passed
dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj \
  --filter "FullyQualifiedName~ScrollAnchorTrackerTests|FullyQualifiedName~StructuredItemsViewAnchorModeTests"

# UI tests, with the HostApp installed on the device: 3 passed on each
DEVICE_UDID=<simulator udid> dotnet test src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj \
  --filter "FullyQualifiedName~CollectionViewAnchorModeEnd"
DEVICE_UDID=emulator-5554 dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj \
  --filter "FullyQualifiedName~CollectionViewAnchorModeEnd"

# Android device tests: 300 passed, 1 skipped (on .NET 11, before the merge that moved the branch to .NET 12)
EmbedAssembliesIntoApk=true pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls \
  -Platform android -Configuration Debug -IncludeClasses "Microsoft.Maui.DeviceTests.CollectionViewTests" -BuildOnly
dotnet xharness android test \
  --app artifacts/bin/Controls.DeviceTests/Debug/net12.0-android/com.microsoft.maui.controls.devicetests-Signed.apk \
  --package-name com.microsoft.maui.controls.devicetests \
  --instrumentation com.microsoft.maui.controls.devicetests.TestInstrumentation \
  --device-id emulator-5554 -o artifacts/log/anchor-android --timeout 00:45:00

# iOS device tests (with a local scene manifest): 170 passed, 4 skipped, on an earlier head. Mac Catalyst: 209 passed,
# 4 skipped. Both ran on .NET 11. For Mac Catalyst, use -f net12.0-maccatalyst -r maccatalyst-arm64 and --target maccatalyst.
dotnet build src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj -c Debug -f net12.0-ios -r iossimulator-arm64
dotnet xharness apple test \
  --app artifacts/bin/Controls.DeviceTests/Debug/net12.0-ios/iossimulator-arm64/Microsoft.Maui.Controls.DeviceTests.app \
  --target ios-simulator-64_27.2 --device <simulator udid> -o artifacts/log/anchor-ios --timeout 00:40:00 \
  --set-env=NUNIT_SKIPPED_CLASSES=Microsoft.Maui.DeviceTests.CollectionViewTests
```

</details>

#### Open questions for API review

1. **Names.** `ScrollAnchorMode` or `ItemsAnchorMode`? I chose
`ScrollAnchorMode` so a vertical `ScrollView` can reuse it later; the
same tracker already works for one. `AnchorMode` matches Blazor, but it
sits next to `VisualElement.AnchorX` and `AnchorY`, which are transform
anchors.
2. **Default.** It's `None`, so existing apps don't change. Blazor's
default is `Start`.
3. **`IsAnchored`** is a `bool` for either edge. Should it say which
edge the view follows, for `Start | End`?
4. **Changing `AnchorMode`** shows the edge it selects. Blazor doesn't
scroll when the mode changes.
5. **Threshold.** The 8-unit threshold is fixed and internal; Blazor
uses 2 px.
6. **Windows:** `AnchorMode` isn't implemented, because it can't be
verified on a Mac. WinUI's `VerticalAnchorRatio` may fit.
`ScrollToStart` and `ScrollToEnd` scroll to the first and last item the
default handler shows, but that's unverified too: the WinUI XAML
compiler doesn't run on macOS, so it hasn't even been compiled here.
7. **Horizontal layouts and right-to-left** aren't anchored.
8. **Snap points.** With mandatory snap points, `ScrollToEnd` ends at
the nearest snap point, as `ScrollTo` does. On Android, `ScrollToStart`
and `ScrollToEnd` drop the item a `MandatorySingle` fling snapped to, as
`ScrollTo` does, so the snap doesn't take the view back to it. Anchoring
isn't designed for snapping lists.
9. **Mac Catalyst's silent offset clamp (#34271).** It doesn't reproduce
on this machine, through a Picker, minimizing and restoring, or a
resize. The anchor still hears of an offset change only KVO reports, and
follows its edge again: a device test simulates one by moving the
layer's bounds with manual KVO notifications.
10. **Overlap with `ItemsUpdatingScrollMode`** (#39491 and #39493, now
in `main`). While the view follows an edge, the anchor keeps it there:
`AdjustScrollForItemUpdate` on Android and
`FinalizeCollectionViewUpdates` on iOS and Mac Catalyst return early.
Otherwise `ItemsUpdatingScrollMode` applies as before. Its default,
`KeepItemsInView`, scrolls the list to its first item as items are
added, so an `End` list the user scrolled away from jumps to its first
item unless the app sets `KeepScrollOffset`. Should `AnchorMode` keep
the offset while the view doesn't follow an edge?
11. **One-shot `ScrollToEnd` without End anchoring** scrolls once. On
Mac Catalyst with accessibility active, UIKit measures rows above the
view 100 to 300 ms after a scroll without keeping the content in place,
which can leave the view 80 to 100 short of the end. After a row
resizes, UIKit also lays offscreen rows and the header out at their
estimated size and measures them again later, which can leave it 30
short. Both are Items2 behavior that predates this PR, and the device
tests allow for them. Should a one-shot `ScrollToEnd` hold the end until
something else scrolls the view, as UIKit holds a `scrollToItem` target?
Or should Items2 keep the content in view in place as UIKit measures
rows above it, for every scroll?
12. **Turning anchoring off** doesn't stop a scroll under way; a review
suggested it should. It isn't a scroll, and stopping one would make
`ScrollTo(item, animate: true); AnchorMode = None;` drop the scroll
while the reverse order keeps it. An animated `ScrollToStart` or
`ScrollToEnd` to the edge the view followed still goes all the way
there. A change to `Start` or `End` does stop it, as it scrolls to that
edge, except on a horizontal layout, which isn't anchored.

### 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. -->

N/A: this is a new feature, and it doesn't fully fix any open issue.
Related:

- #35802 (KeepLastItemInView does nothing on .NET 10 iOS and Android):
not fixed here. `AnchorMode="End"` is the alternative for chats.
- #12036, #29153 (grouped lists): `AnchorMode="End"` follows grouped
lists. This PR doesn't change `KeepLastItemInView`; `main` has since
fixed #29153 (#39491, #39493).
- #29420 (CarouselView): out of scope, because CarouselView isn't a
`StructuredItemsView`.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
…ection update (dotnet#39491)

<!-- 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 Details

When the `ItemsUpdatingScrollMode` is set to `KeepItemsInView,` the
items doesnot scroll to the first item , it maintains the current item

### Root Cause

In the `MauiRecyclerView`, the data change observer is paused for
`KeepItemsInView` in `ItemsUpdatingScrollMode` to maintain the first
position of the item.

### Description of Change

We need to observe the data changes for the `KeepItemsInView` option, as
there may be cases where the item might not remain in view.The issue is
fixed by restarting the data change observer in `MauiRecyclerView`.

### Reference PR : dotnet#27153 

### Issues Fixed
Fixes dotnet#26810 
Fixes dotnet#28006
Fixes dotnet#29153
Fixes dotnet#29145 

### Tested the behaviour in the following platforms
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

### Output Screenshot
Before Issue Fix | After Issue Fix |
|----------|----------|
|<video width="200" height="200" alt="Before Fix video"
src="https://github.com/user-attachments/assets/8adbd870-9c8f-4ac2-bdf2-93301ef0e073">|<video
width="200" height="200" alt="After Fix video"
src="https://github.com/user-attachments/assets/5edb1a05-2a81-46ba-bb1f-353530b4fbc9">|

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
…otnet#40227)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, branched from
`41458556cf5d13573a632b83f89072f8badfb205`. No rebase, retarget, product
change, or merge is included.

### Description of Change

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

Correct the stale `KeepItemsInView` UI-test contract exposed by dotnet#40116.
The [CollectionView
documentation](https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/collectionview/scrolling.md#control-scroll-position-when-new-items-are-added)
and current enum XML documentation specify keeping the **first item in
the list** displayed. dotnet#39491 and dotnet#39493 intentionally implement that
behavior. The remaining Apple test instead expected the previously
visible middle item; the Android branch only checked that this old item
disappeared.

Use the same positive assertions on Android, iOS and MacCatalyst,
retaining the existing Windows exclusion and CollectionView shard.
Verify the initial middle item is actually displayed, insert once, and
positively assert that `cover1.jpg, 0` is displayed. Scroll away again
and verify the new middle identity (`photo.jpg, 9`), then perform the
remaining 24 insertions and positively assert the first item again. This
preserves 25 total updates and prevents the second check from passing
merely because the first insertion already scrolled to the top.

The existing sample inserts at `(Count / 2) - 1`, **not** at index zero;
the first item's identity remains unchanged. No sample IDs, product
behavior, `KeepScrollOffset`, `KeepLastItemInView`, timeouts, retries,
skips, screenshots, tolerances, or CI configuration are changed.
Upstream searches found the existing product fixes above but no
competing test-contract correction.

**Native validation**

Used the original `ui-tests-samples-coreclr` HostApp from
[maui-pr-uitests
1678816](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1678816),
source `fd2f3ce40199b5c48e31a1814a23919f41f6c3d3`, on an isolated iPhone
11 Pro **CoreSimulator iOS 26.5**. The gallery, data source, template,
Apple scroll helper, and both Apple layout implementations have no
source diff between that CI source and this branch's candidate base.
This does not claim the entire binary tree is identical. HostApp
executable SHA-256:
`895101edc9254a6e235051f77cd2bc8e72d4646477b1ed4b308d8de86392396c`.

| Native oracle on the unchanged CI app | Result |
| --- | --- |
| Original Apple test, 25 insertions, old middle-item expectation |
Failed at final `WaitForElement("Vegetables.jpg, 10")`, reproducing CI
(42 s) |
| Corrected positive first-item test | Passed 3/3 (29 s, 31 s, 29 s) |
| Negative mutation: expect the old middle item after the first
insertion | Failed at that wrong-target oracle (25 s) |
| Restored corrected test after the negative mutation | Passed 2/2;
included in the 3/3 above |

Exact test command for the first corrected run (passed 1/1; repeated
with separate result/log paths for the other runs):

```sh
DEVICE_UDID=05DEC405-3AC9-4F2E-8DBC-8B75A0CF9F4C PLATFORM_VERSION=26.5 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/appium-corrected.log dotnet test artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net11.0/Controls.TestCases.iOS.Tests.dll --filter 'FullyQualifiedName~KeepItemsInView' --logger 'trx;LogFileName=corrected.trx' --results-directory /Users/kubaflo/.copilot/session-state/1a025737-fc40-4295-929e-719007b50025/files/native-corrected
```

The native HostApp was **not rebuilt** using the locally installed Xcode
27.2 or SDK-check bypasses. Only the platform-neutral net11.0 NUnit
runner was rebuilt using installed .NET SDK 11.0.100. The artifact route
deliberately avoids the local HostApp runner's source rebuild and
shutdown of other sessions' simulators. An initial overly specific
discovery filter selected zero tests; it was corrected to the command
above before collecting these outcomes.

Exact compilation/formatting commands and results:

```sh
# Passed: iOS NUnit runner, final corrected source.
dotnet msbuild src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Android NUnit runner compilation; not an Android native execution.
dotnet msbuild src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed: Catalyst NUnit runner compilation; not a Catalyst native execution.
dotnet msbuild src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj -restore -t:Build -p:IncludeAndroidTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -v:q -nologo
# Passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/CollectionViewUITests.CollectionViewItemsUpdatingScrollMode.cs --verify-no-changes --verbosity quiet
# Passed.
git diff --check
```

Native Android and MacCatalyst execution and full-suite CI are not
claimed. No duplicate candidate-wide CI run was queued; candidate-wide
coverage remains coordinated separately.

### 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. -->

Relates to dotnet#40116, dotnet#39491, and dotnet#39493. These references are
intentionally non-closing; this fixes the test contract, not the
underlying product issues.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
…ng (dotnet#40258)

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

This is explicitly coordinated candidate-validation work targeting
`candidate/11.0.1xx-sr2`, based on
`dca0930d7167052b18c0fa25b1995fa416c2bb06`. No merge, retarget, rebase,
or manual CI/review request is included.

### Description of Change

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

Make the `Github5623` incremental-loading sample explicitly use
`KeepScrollOffset`. Its implicit `KeepItemsInView` default now
intentionally scrolls to the first item after an insertion (dotnet#39491).
That behavior is correct for that mode, but inappropriate for this
sample's continuous user scrolling through asynchronously appended
pages. dotnet#40227's documented first-item contract and the production
implementation remain intact.

The original API30 `Github5623(Android).CollectionViewInfiniteScroll`
oracle reproduced the candidate timeout at
`AppiumTouchActions.ScrollTo:333` / original test line 27. Separate
native diagnostics observed successful page appends `10 -> 20 -> 30 ->
40`, each immediately followed by a native zero-delta callback with the
first cell back at index 0/top 0. These rewinds explain the large
cumulative managed scroll offset despite low visible indexes.
Temporarily removing that native rewind as a **diagnostic control only**
eliminated the resets. The native control and all diagnostic code were
then restored and hash-verified before committing.

The committed change is exactly one XAML attribute. The original NUnit
method, discovery of item `12` by actual user gestures, random 20-319
item heights, `MeasureAllItems`, threshold 25, initial/page size 10,
loading implementation, original 15-second `ScrollTo` deadline, waits,
assertions, retries, categories, and screenshots are unchanged. This is
a sample contract correction, not a production rollback or a weakened
test.

Upstream open/recently merged PR searches covered `Github5623`, infinite
scrolling, `KeepItemsInView`, and `KeepScrollOffset`, together with the
exact sample file history. They identified dotnet#39491 and dotnet#40227 but no
competing sample repair.

**Native evidence**

Used one task-owned API30 Google APIs ARM64 Nexus 5X emulator, 1080x1920
at 420 dpi, with .NET SDK 11.0.100/runtime 11.0.0, source-built Release
HostApp, embedded assemblies, and the original Android NUnit assembly.
Appium transport alone was adapted locally to private ports
4793/8293/7893 and the owned emulator; that adaptation is not committed.
No physical Apple device or host macOS XCTest automation was used.

| Phase | Actual cases | Result |
| --- | --- | --- |
| Unchanged original sample/oracle | 1 | Failed: exact scrolling-to-12
timeout, 18.233251 s |
| Instrumented native trigger-removal control, not the published fix | 1
| Passed, 7.563766 s; appends retained without rewind |
| Non-instrumented sample-only fix | 3 | Passed: 10.791304 / 8.946879 /
8.947579 s |
| Revert only the sample attribute, restore and rebuild original sources
| 1 | Failed: same scrolling-to-12 timeout, 17.930881 s |
| Restore fix, rebuild immutable
`026e646e5f820804ca655813a9a5c0e83e40e115` | 3 | Passed: 8.922002 /
11.637289 / 10.590518 s |
| Unchanged original `TestCategory=CollectionView2` selector on that
pushed immutable head | 77 | **77 passed, 0 failed, 0 skipped**;
original infinite-scroll case passed in 7.278173 s |

Raw TRX and NUnit XML were checked independently and retained for every
invocation. A separate diagnostic run with the original rewind still
enabled passed in 16.054472 s and is **not** counted as a
non-instrumented baseline pass. Five initial zero-test selector
invocations and one Appium argument-quoting setup failure are retained
separately; none establishes an original-oracle outcome.

Immutable-head APK SHA-256:
`1b3cf5c30f5c001919874e540f52183cf41d346a4b7b2bcfa8ab4b1cd687b9f8`.

**Limits:** the local causal chain proves the sample repair on API30
ARM64/.NET 11 GA, and the completed exact-source API30 CI suite below
now supplies CI-servicing confirmation for the original 77-case Android
suite. Other-platform and whole-pipeline clearance are not claimed. The
supplied newest exact-target CI case was green; this PR does not claim
that the latest target was red or that the unrelated managed-unit
correction caused the failure. Candidate-wide CI remains
parent-coordinated.

**CI validation and remaining limits (2026-11-14 UTC snapshot)**

The live PR remains at head `026e646e5f820804ca655813a9a5c0e83e40e115`,
candidate base `dca0930d7167052b18c0fa25b1995fa416c2bb06`, and synthetic
merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. The human-issued
review, rebase, and pipeline requests on November 14 did not change
those source identities.

The earlier [maui-pr
1681455](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681455)
and [maui-pr-uitests
1681457](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681457)
were **canceled**, not complete passing runs. Before cancellation, the
four managed-unit Helix jobs completed and all **50 product work-item
XML reports** were audited, excluding controller work items, with no
named failures, assembly errors, or XML/count gaps. In each of
Debug/Release on macOS ARM64/Windows x64, Core recorded **1,125 passed,
0 skipped** and SourceGen **733 passed, 53 existing gated skips**. Those
skips are not passes; configuration counts are not summed into a
unique-test total. This source does not include the separate metadata
correction in dotnet#40252. Completed unit XML evidence remains valid despite
cancellation; it does not establish a full build, pack, integration, UI,
or device-test pass.

The human-requested replacement runs use the **same synthetic merge**.
They were initially confirmed **in progress**; the later terminal
UI/device status and remaining main-pipeline coverage are recorded
below:

| Pipeline | Existing replacement run | Queued (UTC) |
| --- | --- | --- |
| `maui-pr` |
[1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489)
| 16:45:42 |
| `maui-pr-uitests` |
[1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
| 16:45:45 |
| `maui-pr-devicetests` |
[1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
| 16:45:48 |

Reuse those runs; no additional pipelines or reviews were queued for
this description update. The native causal chain and original local **77
passed / 0 failed / 0 skipped** result above remain separate evidence,
not replacement-CI results.

The human-requested `maui-copilot` review gate
[16033607](https://dev.azure.com/DevDiv/DevDiv/_build/results?buildId=16033607)
is
**[INCONCLUSIVE](dotnet#40258 (comment):
provisioning stopped before verifying/checking out the PR head,
establishing a baseline, or running tests. Its trusted runner source
`e1140933230eabacbaf6412c0b8d80ece38f2d48` is not the tested PR source.
Original Azure raw log 12 contains 32 physical lines; lines 13, 21, and
29 repeat the protection refusal across the three existing setup
attempts: "The new servicing/staging target must have branch protection
before credential-bearing provisioning can run. Refusing to switch."
GitHub independently reports `candidate/11.0.1xx-sr2` as
`protected=false`.

This gate supplied **no test execution or causal-baseline result**. It
is not a test-red verdict or evidence against the sample fix. Deploying
the required candidate branch protection is a **maintainer action**; do
not bypass or modify the guard. Full replacement-CI outcomes and a
successfully provisioned review gate remain outstanding.

**Later CI/review evidence (2026-11-14 UTC)**

[Expert review
5905946810](dotnet#40258 (review))
reviewed exact head `026e646e5f820804ca655813a9a5c0e83e40e115` and
reported **zero findings**. Its state is `COMMENTED`, not human approval
or a successful runtime gate. Candidate protection is still `false`; the
provisioning gate described above remains blocked.

In [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
at the same `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` merge, the
**CoreCLR device-test build failed before runtime execution**. Original
raw log 63 records nine CA1416 diagnostics while compiling Essentials
`net11.0-ios27.0`: three deprecated `UIGraphics` calls in
`MediaPicker/ImageProcessor.ios.cs` and six availability calls in
`Passkeys/Passkeys.ios.cs`. The original binlog confirms those nine
diagnostics plus one outer `BuildFailed`, not independent faults in
every downstream project. Three dependent CoreCLR runtime stages were
skipped, leaving a coverage gap.

Those two Essentials source files are byte-identical on the target and
candidate. The actual candidate control [device run
1681310](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681310),
source `77a87edc03aa2728d7e0a51050da0e424a82c801`, completed the CoreCLR
build successfully with zero errors (original raw log 67). This build
failure is unrelated to the sample's one XAML attribute; the precise
analyzer-input divergence remains **unproven**. No speculative
availability/source fix or analyzer suppression is proposed.

Completed portions of [replacement UI run
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490),
on the same merge, supply separate unchanged MacCatalyst evidence:
CollectionView7 run **46901196** recorded **52 passed, 0 skipped**,
including both dotnet#31899 header/footer cases, with no retry; mixed drag
shard run **46901170** recorded **57 passed, 1 existing skip**,
including the dotnet#12060 and dotnet#28416 cases, with no retry. These are not
evidence of a causal MacCatalyst repair by this Android
incremental-sample change.

The MacCatalyst Navigation shard still has **two failures on both the
original attempt and existing retry**: dotnet#21814 receives an empty
navigation-event string, and dotnet#23902 receives "NavigatedTo called 2
times" instead of 3. Original raw log 3790 and publisher log 3792
correlate to run **46901248** (**85 passed, 2 failed, 1 skipped**);
failure details are
[dotnet#21814](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087)
and
[dotnet#23902](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086).
These repeat separately observed candidate/branch failures and are not
attributed to the unrelated sample delta.

The replacement Android `Github5623`/original 77-case CollectionView2 CI
result is published and passed on its first attempt, as detailed below.
Overall UI run **1681490** and device run **1681491** have completed
failed; main run **1681489** remains in progress with passing
Build/Pack/Unit stages and incomplete integration coverage. Keep the
original local causal/full-77 evidence distinct from completed CI shard
results, recovered initial failures, and remaining pipeline outcomes. No
new queues, review replies, source changes, or protection changes were
made.

**Completed exact-source Android CI (2026-11-14 UTC)**

The original API30 CollectionView2 suite completed in [maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
at synthetic merge `b79d6d1607e0fe3707f502bbde84ffbe1ac07c23` (PR head
`026e646e5f820804ca655813a9a5c0e83e40e115`, candidate base
`dca0930d7167052b18c0fa25b1995fa416c2bb06`). [Original run
46901428](https://dev.azure.com/dnceng-public/public/_TestManagement/Runs?runId=46901428&_a=runCharts)
recorded **77 passed, 0 failed, 0 skipped on the first attempt**. The
actual [Github5623(Android).CollectionViewInfiniteScroll result
100042](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901428/Results/100042)
passed in **9,353 ms**, without a harness retry.

Original Azure [raw log
4026](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4026)
contains 1,254 physical lines and the successful 77-pass summary, with
no failed case or harness retry. [Publisher log
4028](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1681490/logs/4028)
links those exact 77 results to run 46901428. All 77 automated names and
their multiplicities match actual-candidate original run 46895912; the
selector, original oracle, and 15-second scroll deadline were not
reduced or changed. This closes the previously recorded local
ARM64/GA-versus-CI-servicing runtime gap **for this original Android
suite only**; the local causal chain remains independently documented
above.

This is not a whole-pipeline or other-platform clearance. The two
MacCatalyst Navigation failures above remain. A separate MacCatalyst
[dotnet#25074
result](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228)
fails `ButtonResizesWhenTitleOrImageChangesAltered.png` with **1.14%
difference on both the original attempt and existing retry**; it is
unrelated to this sample delta, not an Android-oracle failure. The
CoreCLR availability-build failure and skipped-runtime coverage gap in
device run 1681491 remain; that overall device run has completed
**failed**, as has UI run 1681490. Candidate protection is still
`false`, so the runtime review gate remains blocked despite the
exact-head zero-findings expert review. Main run 1681489 has passing
Build/Pack/Unit stages, but its incomplete Integration stage prevents a
whole-main pass. The full terminal UI and measured integration scopes
are detailed below. No new queues, review replies, source changes, or
protection changes were made.

**Terminal UI audit and remaining validation (2026-11-14 UTC)**

[maui-pr-uitests
1681490](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681490)
has completed **failed** at exact merge
`b79d6d1607e0fe3707f502bbde84ffbe1ac07c23`. All **129 original UI task
raw logs**, their own publishers, and **129 actual final result sets**
were audited. Final published records across platforms/categories are
**14,907 passed, 302 NotExecuted, 3 failed**. These are execution
records, **not unique methods or first-attempt green results**. Nineteen
eventually successful tasks retain **71 original failed records** in
their raw logs; retry recovery does not erase those failures or
establish causal repairs. Every raw failure method name appears in a
corresponding final run, but this is a method-name presence check, not a
claim of fully qualified oracle identity equivalence.

The only three final failures are the MacCatalyst cases already
documented: [dotnet#25074's 1.14% altered-button
snapshot](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901776/Results/100228),
[dotnet#23902's two-versus-three navigation
count](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100086),
and [dotnet#21814's empty navigation-event
text](https://dev.azure.com/dnceng-public/public/_apis/test/Runs/46901248/Results/100087).
The original Android API30 CollectionView2 suite above remains **77
passed, 0 failed, 0 skipped on its first attempt, with no harness
retry**; the full terminal audit independently preserves its original
log 4026, publisher 4028, and run 46901428. The unrelated Mac failures
do not invalidate that exact Android result.

[maui-pr
1681489](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681489),
on the same merge, now has completed passing **Build, Pack, and Helix
Unit Test stages**, but **the whole pipeline is not yet passed**. Only
**20 of 23 original integration tasks** have completed measured
summaries: **311 passed, 10 existing skips, 0 failed** in those
completed tasks. Three tasks remain unmeasured/in progress:
`mac_buildtemplate_previous_tests`, Windows `Build`, and Windows
`Blazor`. Their absent results are not zero failures or passes.

Terminal [device run
1681491](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1681491)
remains **failed**. Its **31 available product XML reports** contain
**22,318 passed, 2 existing Windows Border failures, 549 existing
skips**, with available per-assembly counts checked and no
assembly-error/count gaps. Skip identities, reasons, and multiplicities
match the candidate; counts span available execution/configuration
records, not unique methods. The nine-CA1416 CoreCLR compile failure and
three skipped dependent runtime stages remain a separate coverage gap:
available XML results do not certify the missing CoreCLR matrix.

The PR head, candidate base, and synthetic merge are unchanged.
Candidate protection remains `false`, the provisioning review gate
remains blocked, and zero-findings expert review is still not human
approval or runtime-gate success. No source changes, pushes, new queues,
review replies, or protection changes were made for this validation
update.

**Exact validation commands and results**

```sh
# Passed: Android-only repository build tasks.
dotnet build ./Microsoft.Maui.BuildTasks.slnf -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:BuildTaskOnlyBuild=true -v:q -nologo

# Passed for original, diagnostic control, fixed, reverted, restored, and immutable-head builds.
dotnet build src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj -c Release -f net11.0-android -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -p:RuntimeIdentifier=android-arm64 -p:EmbedAssembliesIntoApk=true -v:q -nologo

# Passed: original Android NUnit runner, with private transport only.
dotnet build src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=true -v:q -nologo

# Same command for each original-oracle phase; $resultdir selected a separate retained phase/attempt directory.
# Results are the actual cases in the phase table above; no automatic test retry was added.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE="$resultdir/appium.log" dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'Name=CollectionViewInfiniteScroll' --logger 'trx;LogFileName=original.trx' --results-directory "$resultdir" -v:q -nologo -- "NUnit.TestOutputXml=$resultdir/nunit"

# Passed: original 77-case selector, after pushing and verifying the exact immutable head.
DEVICE_UDID=emulator-5582 DEVICE_SKIN=Nexus_5X PLATFORM_VERSION=11 HEADLESS=true APPIUM_LOG_FILE=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/appium.log dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj -c Release --no-build --no-restore --filter 'TestCategory=CollectionView2' --logger 'trx;LogFileName=collectionview2.trx' --results-directory /Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2 -v:q -nologo -- NUnit.TestOutputXml=/Users/kubaflo/.copilot/session-state/0f3d8462-8297-42f8-95e8-06e582359747/files/original-collectionview2/nunit

# Passed.
xmllint --noout src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml
# Passed.
git diff --check

# Not completed: bounded/stopped during full-solution loading without output; no formatting pass claimed.
# Only XAML changed; native XAML compilation and XML syntax checks above passed.
dotnet format Microsoft.Maui.sln --no-restore --exclude Templates/src --exclude-diagnostics CA1822 --include src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Github5623.xaml --verify-no-changes --verbosity quiet
```

Direct source build/install/NUnit commands mirror the existing Cake
UI-test recipe and deliberately avoid the local wrapper's global ADB
restart/recovery behavior in this shared environment. Pre-existing
emulators and their ADB server were preserved.

### 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. -->

Relates to dotnet#40116, dotnet#39491, and dotnet#40227. These references are
intentionally non-closing; this corrects the incremental-loading
sample's scroll-mode contract.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
…View in view (dotnet#40211)

<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `0a18c2b26b92e131c5962f1686da929a504392f1`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 7.5/10 | ↑ Merged with `main` at dfca8ad37c, which
moves the repo to .NET 12 (#40060). Only the six Controls PublicAPI
files conflicted, resolved as the exact union of both sides.<br>↑ With
the pinned .NET 12 SDK: Controls.Core builds for net12.0, netstandard2.0
and netstandard2.1 with the PublicAPI analyzers, 0 warnings.
`Controls.Core.UnitTests`: 7033 pass, 30 skipped, including the 108
anchor tests.<br>↑ Each review fix was reproduced by a test that failed
before it.<br>↑ Before this merge, on .NET 11: Android API 37, 300
`CollectionViewTests` pass; Mac Catalyst (macOS 27.2.1), 209 pass.<br>↓
Not built or run locally on .NET 12 for Android, iOS or Mac Catalyst:
this machine has no .NET 12 workloads, and too little free disk to
install them.<br>↓ CI on this head is pending: maui-pr builds every
platform on .NET 12; uitests and devicetests need a maintainer's `/azp
run`.<br>↓ With `main`'s default `KeepItemsInView`, a list the user
scrolled away from jumps to its first item as items are added unless the
app sets `KeepScrollOffset`. |
<!-- /copilot-assessment -->

<!-- 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!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

This is a new feature with new public API, so it targets `main`.

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

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

Chat, AI-streaming, log and feed screens need a list that keeps one edge
of its content in view while the content changes:
- **The end**, for chats and logs. This includes while the last item
grows in place as an answer streams in.
- **The start**, for feeds that add the newest items at the top.

The list must stop following when the user scrolls away to read, and
start again once they're back at that edge. CollectionView can't do this
today, so every app writes its own scroll tracking. The hard part of
that tracking is telling a user's scroll apart from the platform moving
the offset while rows re-measure.

`ItemsUpdatingScrollMode.KeepLastItemInView` doesn't cover it:
- it only reacts to collection changes;
- it scrolls even while the user reads history;
- it stops at the last item, short of a footer.

Blazor's `Virtualize` added the same capability in .NET 11 for the same
scenarios (`VirtualizeAnchorMode`, dotnet/aspnetcore#65742). This PR
builds the behavior of the dotnet/maui-labs prototype
(dotnet/maui-labs#842) into CollectionView itself, with the same modes
as Blazor.

#### API

```csharp
[Flags]
public enum ScrollAnchorMode
{
    None = 0,   // today's behavior, the default
    Start = 1,  // follow the start: feeds that add the newest items first
    End = 2,    // follow the end: chats, logs, feeds that append
}

public partial class StructuredItemsView
{
    public static readonly BindableProperty AnchorModeProperty;
    public ScrollAnchorMode AnchorMode { get; set; }

    public static readonly BindableProperty IsAnchoredProperty;
    public bool IsAnchored { get; }                   // read-only: whether the view follows an edge right now

    public void ScrollToStart(bool animate = true);   // to the start of the content, header included
    public void ScrollToEnd(bool animate = true);     // to the end of the content, footer included
}
```

The handlers gain `MapAnchorMode` (`CollectionViewHandler2` on iOS and
Mac Catalyst, `StructuredItemsViewHandler<TItemsView>` on Android).
These overrides also show up in `PublicAPI.Unshipped.txt`, because the
anchor listens to the platform's own callbacks:
- `MauiRecyclerView.OnScrolled` and `OnScrollStateChanged`
- `ItemsViewController2.ViewDidLayoutSubviews`
- `ItemsViewDelegator2.DraggingStarted`, `DraggingEnded` and
`DecelerationEnded`

```xml
<CollectionView x:Name="messages" AnchorMode="End" ItemsSource="{Binding Messages}" />
<Button Text="Jump to latest" Clicked="OnJumpToLatest"
        IsVisible="{Binding IsAnchored, Source={x:Reference messages}, Converter={StaticResource InvertedBool}}" />
```

```csharp
void OnJumpToLatest(object sender, EventArgs e) => messages.ScrollToEnd();
```

#### Compared with Blazor's `Virtualize.AnchorMode`

| | Blazor `Virtualize` | `CollectionView` |
| --- | --- | --- |
| Modes | `None`, `Start`, `End`, as flags | the same names and values |
| Default | `Start` | `None`, which keeps today's behavior |
| `Start \| End` | pins both edges; the end wins when the list is at
both | follows whichever edge the view is at, and the end when it's at
both |
| Detecting prepends | `ItemComparer` for `ItemsProvider` sources | not
needed: the anchor measures the content's offset and extent, not items |
| Whether it follows now | not exposed | `IsAnchored`, bindable |
| Back to an edge | the app scrolls the container | `ScrollToStart` and
`ScrollToEnd`, which reach past the header and footer and follow that
edge again |
| Near-edge threshold | 2 px | 8 device-independent units |

#### Behavior

- **`End`:**
  - The view shows the end of its content when it first appears.
  - It keeps the end in view while:
    - items are added or removed;
    - any item grows or shrinks, the last one included;
    - the header or footer changes, in grouped lists too;
    - the viewport resizes.

"The end" means the end of the content, footer included, not the last
item. Following never animates.
- **`Start`** does the same for the start of the content, above the
header. Items inserted before the first item while the view is at its
start come into view instead of landing above it.
- **`Start | End`:**
  - The view starts at the end and follows whichever edge it's at.
  - When it's at both, because its content fits, it follows the end.
- **Changing modes:** Changing `AnchorMode` starts over, as when the
view first appears. Replacing `ItemsSource` or changing `IsGrouped` does
too.
- **Scrolling away:** A user scroll more than 8 device-independent units
away from the edge stops following, and `IsAnchored` becomes `false`. So
does a scroll the user isn't making, such as one from the keyboard,
accessibility, a status-bar tap, or code moving the native view, also
right as a fling or an animated scroll ends. On iOS and Mac Catalyst
17+, a scroll UIKit animates, such as a status-bar tap or code animating
the native view, counts as a fling until it ends, as a smooth scroll
does on Android. None of these stop it:
  - content growing during the gesture;
  - a bounce;
- offset changes the platform makes while laying out, even when the
content ends up the size it started.
- **Scroll requests:**
- A `ScrollTo` from the app is judged by where it lands. Animated, it
carries on as the content changes on the way, and doesn't take the view
back to the edge it left.
  - The latest request wins:
- a `ScrollTo` right after `ScrollToEnd` isn't undone by following the
end;
- a `ScrollTo`, or a change of `AnchorMode`, made from the `Scrolled`
event or the `IsAnchored` change that `ScrollToStart` or `ScrollToEnd`
raises wins over them, also when it turns anchoring off, and so does a
`ScrollTo` from the `Scrolled` event that replacing `ItemsSource`
raises;
- a `ScrollToStart` or `ScrollToEnd` made from the `Scrolled` event that
a `ScrollTo` raises, or from the `RemainingItemsThresholdReached` that a
`ScrollTo` raises as it stops a scroll, wins over that `ScrollTo`;
- a `ScrollToEnd` or `ScrollToStart`, or a change of `AnchorMode` to
`Start` or `End`, right after an animated `ScrollTo` stops that
animation;
- an animated `ScrollToStart` or `ScrollToEnd` right after one to the
other edge that doesn't animate goes to its own edge;
- an animated `ScrollTo` right after a `ScrollToStart`, `ScrollToEnd` or
`ScrollTo` that doesn't animate goes to its item;
- a `ScrollTo` for an index the items don't have, before the first or
past the last, leaves what an earlier scroll is still finishing as it
is.
  - A `ScrollTo` that finds nothing to scroll to changes nothing.
- Reaching the edge again, however the view gets there, starts following
again.
- **`ScrollToStart` and `ScrollToEnd`:**
- They scroll above the header or past the footer, which `ScrollTo(0)`
and `ScrollTo(lastIndex, position: End)` can't reach.
- With the matching mode, the view follows that edge from the moment
it's asked to. "Jump to latest" never sees `IsAnchored` flash `false` on
the way, also while the platform measures the rows an animated one
brings into view. A scroll the user isn't making that stops an animated
one on its way, such as code moving the native view or a status-bar tap,
leaves the view where it stopped, judged as any other scroll. An
animated one to the edge the view is at already doesn't animate, and a
scroll away right after it is judged as any other.
- Without it, they scroll there once. They go the rest of the way once
the rows they brought into view are measured. Animated, they carry on as
the content changes on the way, such as an answer streaming in, and
don't take the view back to the edge it left. A scroll that stops an
animated `ScrollToStart` on its way, such as code moving the native
view, leaves the view where it took it.
  - Like `ScrollTo`, they do nothing before the view has a handler.
- **Turning anchoring off:** Setting `AnchorMode` to `None` stops
following at once, even from a `Scrolled` handler that the anchor's own
correction raised. It isn't a scroll: the view stays where it is, and a
scroll under way, such as an animated `ScrollTo`, carries on. An
animated `ScrollToStart` or `ScrollToEnd` to the edge the view followed
still goes all the way there, as it does without the mode.
- **`ItemsUpdatingScrollMode`:** While the view follows an edge,
`ItemsUpdatingScrollMode` doesn't scroll it. Otherwise that mode applies
as usual, and this PR doesn't change any mode. On `main`,
`KeepItemsInView`, the default, now scrolls the view to its first item
as items are added (#39491, #39493), also a view the user scrolled away
from an edge; `KeepScrollOffset` leaves it where the user scrolled. The
`AnchorMode` remarks say so.

#### How it works

- An internal, platform-agnostic `ScrollAnchorTracker` makes every
decision, following one edge at a time. Its inputs are the offset,
content extent and viewport that the platform reports after each layout
and scroll. Measuring the content extent, rather than tracking items, is
what makes groups, headers, footers and growing items work. The unit
tests spell out its rules.
- The platform code only reads native metrics and scrolls. It uses the
handlers' own signals, with no extra gesture recognizers or external
listeners:
  - **iOS and Mac Catalyst (Items2):**
- Layout: `ItemsViewController2.ViewWillLayoutSubviews` and
`ViewDidLayoutSubviews`. UIKit also lays the view out when the
controller sets a new layout (a header or footer replaced) and when the
items source applies items added, removed or moved. It can move the
offset there before it updates the content size, so the controller
brackets those updates as layout too.
- Scrolling: the `Scrolled`, `DraggingEnded` and `DecelerationEnded`
callbacks on `ItemsViewDelegator2`. A scroll the user isn't making is
judged straight away in `Scrolled`, before the layout pass that measures
the rows it brings into view. It's judged as a new scroll, also right
after a drag, a deceleration or an animated scroll ended, before the
layout pass that looks at where that one stopped. If the content or the
viewport changed size since the anchor last looked, the offset moved for
that change, as when the keyboard manager sets the view's insets, and
it's judged as layout.
- One-shot scrolls: a `ScrollToEnd` without End anchoring finishes in
the layout passes after it, because UIKit estimates rows at 30 points
until it measures them. It finishes only in a layout pass UIKit runs on
its own: one it forces right after the scroll may not have measured the
rows there yet.
- An animated `ScrollToStart` or `ScrollToEnd` to an edge the view
doesn't follow counts as a fling until UIKit reports that its animation
ended, the user drags, or the app requests another scroll, as a
requested smooth scroll does on Android. The anchor used to judge it in
the layout right after the request, before the animation moved the view.
So it followed the edge the view was leaving again, and a row measured,
grown or added before the view got clear of that edge scrolled it back
there, which stopped the animation. UIKit doesn't animate a view that
isn't in a window: it scrolls the view there and reports that the
animation ended before the call returns. The controller counts those
reports, so such a request is done at once, and `ScrollToEnd` goes the
rest of the way as from the end as laid out.
- UIKit keeps the rows in view in place as it measures the rows an
animated scroll to the start brings into view above them, so the
animation stops short of the start by as much as those rows grew. A
one-shot `ScrollToStart` goes the rest of the way once the animation
ends, unless the view stopped further from the start than the content
grew meanwhile, plus 8 units. A scroll stopped the animation then, such
as code moving the native view, and the view stays where that scroll
took it. It used to jump to the start whenever the animation ended.
- A scroll UIKit animates that the anchor didn't start, such as code
animating the native view or a status-bar tap, counts as a fling while
`ScrollAnimating` says it animates (iOS and Mac Catalyst 17+), and the
anchor looks again once UIKit reports its end. It used to be judged as a
scroll the user isn't making: within 8 units of the edge it was leaving,
the view still followed that edge, and a row UIKit measured, or the
content growing, as the animation started took it back there, which
stopped the animation. Before iOS 17 it's judged as before.
- An animated `ScrollTo` counts as a fling the same way while UIKit
animates it. UIKit doesn't animate a scroll to where the item already
is, and never reports an end for it, so the controller checks
`UIScrollView.ScrollAnimating` (iOS and Mac Catalyst 17+) once the
request returns. The anchor used to judge the request in the first
layout, before the animation moved the view: from the end of a list that
follows its end, it kept following the end, and the content changing
then scrolled the view back there, which stopped the animation. Before
iOS 17, which doesn't tell (Mac Catalyst's minimum is 17), it's judged
in the first layout, as before: a content change between that layout and
the animation's first frame still takes the view back to the end there.
- An animated `ScrollToStart` or `ScrollToEnd` to the edge the view
follows keeps following that edge until it gets there. UIKit reports
when its animation ends. An end short of where the animation was going
was a scroll stopping it, such as code moving the native view or a
status-bar tap, unless the anchor's own correction stopped it, UIKit
stopped it while laying the view out, or the content or the viewport
changed size. The anchor then judges where the view stopped. It used to
keep following the edge, so `IsAnchored` stayed `true` and the next
content change pulled the view to the edge. A drag or a newer request
forgets the animation, so the stop that `ScrollToStart` and
`ScrollToEnd` make before they scroll isn't judged.
- An animated `ScrollToStart` or `ScrollToEnd` to the edge the view
follows and is at already doesn't animate, and UIKit reports no end for
it. It now jumps there, as one that doesn't animate does, which judges
where the view is at once. It used to follow the edge as for an
animation on its way there: a scroll away right after it was ignored,
and the rows that scroll brought into view pulled the view back to the
edge.
- A grouped list that measures all its items scrolls to the item again
once an animated `ScrollTo` ends, as on `main`. It now waits for that
end only when UIKit reports one: on iOS and Mac Catalyst 17+ when
`ScrollAnimating` says the scroll animates, and before 17 when the view
is in a window. Otherwise it scrolls again at once. A view that isn't in
a window doesn't animate, and UIKit reports the end before the scroll
returns, so the callback registered after the scroll ran at the end of a
later, unrelated animation, which scrolled back to the item. UIKit never
reports an end for a scroll to where the item already is, either.
- Requests are numbered by the controller. A `ScrollTo`, `ScrollToStart`
or `ScrollToEnd` that a newer request or mode change superseded from its
own `Scrolled` event stops there, also from the layout `ScrollToStart`
and `ScrollToEnd` force before they scroll, and a superseded `ScrollTo`
doesn't arm Mac Catalyst's restore (#34271).
- UIKit records a `scrollToItem` target and applies it again in later
self-sizing layout passes, unless the view really scrolled after
`scrollToItem` returned. So a `ScrollToStart` or `ScrollToEnd` requested
while `ScrollTo` is inside `scrollToItem` runs once it returns.
- Mac Catalyst can move the offset without telling the scroll view
delegate or laying the view out (#34271, #36431). The anchor hears of
that through the `contentOffset` KVO observer `MauiCollectionView`
already has, counts the move as the platform's, and follows its edge
again, replacing the restore of a `ScrollTo` that anchoring clears. The
anchor clears that restore whenever it reports that the view follows an
edge, also when the view got back to it without a drag, as the keyboard
or accessibility scroll it: the restore would otherwise take the view
back to the item when the anchor moves it up as the content shrinks. The
observer tells the controller directly, through a listener it holds
weakly rather than an event, so it doesn't allocate on every scroll
tick.
- While anchored, `LayoutFactory2.FinalizeCollectionViewUpdates` returns
early.
- A mode change stops an animated scroll the app requested, as the view
goes to the edge it now follows. A horizontal layout isn't anchored, so
there a mode change leaves the scroll, the grouped scroll's callback and
Mac Catalyst's restore alone.
- Turning anchoring off while an animated `ScrollToStart` or
`ScrollToEnd` is still on its way to the edge the view followed hands
that scroll to the step that finishes a one-shot scroll once its
animation ends, unless the app requested a newer scroll. Without it, the
scroll stopped where its animation ended, short of an edge that rows
measured on the way had moved.
  - **Android:**
- Signals: `MauiRecyclerView.OnLayout`, `OnScrolled` and
`OnScrollStateChanged`, plus an adapter data observer like the ones
`EmptyView` and `ItemsUpdatingScrollMode` use. RecyclerView keeps the
first row it shows in place as it applies item changes, so the offset
moves even when the content stays the same size. The look after the
layout that applies them counts that move as the layout's. While
anchored, `AdjustScrollForItemUpdate` returns early. The look at a view
whose scroll went idle is posted to the next frame: a scroll reported
before it is judged as a new one, not as the end of the gesture.
- Measuring: RecyclerView's `computeVerticalScrollOffset` and
`computeVerticalScrollRange` are estimates based on the average row
size, so the anchor measures from the laid-out rows instead. The offset
follows a reference row, identified by its view *and* its adapter
position, because RecyclerView reuses a row's view for another row even
within one frame of a fast scroll. Without the first row laid out, the
offset comes from rows laid out before, or from the estimate, which can
be far off with rows of very different heights. A row above the view can
also change size while it isn't laid out: an item replaced, or resized
by a binding, which nothing reports until the row is laid out again. So
the view isn't taken to be at the start until the first row is laid out.
When the first row is laid out again after the offset came from the
estimate, the view moved only as far as the row it kept in view, or the
scroll, says: the anchor tells the tracker that the rest is a new origin
(`ScrollAnchorTracker.MoveOrigin`), not movement. A single scroll away
from the end, by code moving the native view, that first laid out a
first row much taller than the others used to look like a move toward
the end, and the list was pulled back there.
- `ScrollTo` from inside a layout: RecyclerView raises `Scrolled` as it
lays out, and Android drops a layout that a view requests during its own
layout. So a jump requested from there used to land only at some later,
unrelated layout. `ScrollHelper` now requests the layout again once the
current one is over. The adjustment the jump leaves (centering or ending
an item, or reaching the end of a last row taller than the view) waits
for that layout too, instead of running at the end of the current one,
before the jump has scrolled. The anchor judges that request in the
layout that lands it. A correction the anchor has to post the same way,
because the row at the edge isn't laid out yet, leaves the tracker
measuring from where the view was
(`ScrollAnchorTracker.DeferCorrection`), as a scroll can move the view
first: the next look judges that scroll, which stops following the edge
if it took the view away, and otherwise asks for the correction again.
- `ScrollTo(index, groupIndex)` now computes the adapter position from
the group sizes, as the flat index already did. It used to look the item
up one position on (right only for groups with a header) and then search
for an equal item, so it skipped an item, or threw, in groups without a
header, and could land on an equal item in an earlier group. Device
tests call it for a group without a header and for an item equal to one
in an earlier group.
- A `ScrollTo` that doesn't animate, for an index the items don't have
(past the last item, or the header's or footer's position), no longer
replaces a scroll requested before it that hasn't been laid out yet, as
iOS ignores such indices. Animated, it still scrolls there, or to the
last item for an index past it.
- Turning anchoring off while the anchor reports `IsAnchored` stops an
animated scroll to an edge it was about to start. `ScrollToStart` and
`ScrollToEnd` drop a `MandatorySingle` fling's snap target, as
`ScrollTo` does, so the snap doesn't take the view back to it.
- A mode change or a new `ItemsSource` stops an animated scroll the app
requested, all the way to where it ends, as the view goes to the edge it
now follows. RecyclerView's smooth scroller stops once it finds its
target and leaves the rest of the scroll to RecyclerView, which settles
it as it settles a fling, so `IsSmoothScrolling` is `false` for that
last stretch. `MauiRecyclerView` remembers that the scroll is the app's
until the view stops or the user drags it. A fling of the user's still
carries on. On a horizontal layout, which isn't anchored, a mode change
doesn't stop the scroll, and isn't a newer scroll request: a `ScrollTo`
that doesn't animate still jumps to its item when the app changes the
mode from the `RemainingItemsThresholdReached` it raises as it stops a
scroll.
- A new `ItemsLayout` that scrolls vertically after one that didn't
starts the anchor over as `MauiRecyclerView` replaces the layout
manager, as a new view does, rather than at the first look after the
next layout. A `ScrollTo` the app requests right after it, in the same
update, is judged by where it lands, as on iOS and Mac Catalyst, where
the controller looks while it swaps the layout. One requested right
before it was for the layout manager it replaced, and gives way to the
new layout.
- Stopping a scroll raises a pending `RemainingItemsThresholdReached` as
RecyclerView goes idle. A scroll the app requests from it is newer than
the request that stopped the view, so the view doesn't go where that
request was going after it: a mode change, or a `ScrollToStart`,
`ScrollToEnd` or `ScrollTo` that doesn't animate. `ScrollToStart`,
`ScrollToEnd` and a `ScrollTo` that doesn't animate stop the view
themselves before they jump, with or without a matching anchor, because
RecyclerView's `scrollToPosition` would stop it first and then set the
older position.
- An animated `ScrollToStart` or `ScrollToEnd`, with anchoring or
without it, starts once the view is laid out, as iOS lays the view out
before it scrolls. So does one on a horizontal layout, which goes to the
first or last item. RecyclerView's smooth scroller works out how far to
go in the next frame's animation, which comes before that frame's
layout. So a row the app grew with the request moved the end after the
scroll had stopped, and nothing followed it. And a jump to the other
edge that an earlier request left for that layout landed after the
smooth scroller had already stopped, having found its target in place.
The request waits where `ScrollHelper` keeps a jump's adjustment, so a
newer request replaces it. A mode change to `Start` or `End` cancels it,
and the adjustment a jump left, as it stops an animated scroll the app
requested.
- An animated `ScrollTo` whose item is already in place doesn't scroll:
the smooth scroller stops in its first step, and nothing reports that.
The anchor judged the request only at the next content change, after the
change had moved the content, and stopped following the edge the view
was at. It now looks once the smooth scroller has taken its first step,
which judges such a request where the view is, and one that scrolls as a
fling.
- An animated `ScrollTo` for an item starts once the view is laid out
while a jump hasn't been made yet: one from `ScrollToStart`,
`ScrollToEnd` or a `ScrollTo` that doesn't animate, or the anchor's jump
to its edge. RecyclerView makes the jump in the next layout, and the
smooth scroller's first step comes before it: finding the item the view
showed in place, it stopped, and the jump then took the view away.
`ScrollHelper` and the anchor record a jump until that layout. A
`ScrollTo` past the last item, as `KeepLastItemInView` requests, starts
at once as before.
- `ScrollToStart` and `ScrollToEnd` reach the platform through an
internal `IScrollToEdgeHandler`. Where the view can't scroll to an edge
of its content, the handler scrolls to the first or last item it shows,
grouped or not. It finds that item in its own items (the adapter, the
collection view's sections, or WinUI's `CollectionViewSource`), not by
reading `ItemsSource` again, so a sequence that can be read only once
and groups that aren't lists work. Only handlers without the interface
(the obsolete iOS handler, the opt-out Windows `CollectionViewHandler`,
custom handlers) fall back to `ScrollTo` the first or last item
`ItemsSource` gives.

| Platform | `AnchorMode` `Start` and `End` | `ScrollToStart` and
`ScrollToEnd` |
| --- | --- | --- |
| iOS, Mac Catalyst (Items2, the default handler) | vertical layouts |
edges of the content |
| Android | vertical layouts | edges of the content |
| Windows (Items2, the default handler) | not implemented, `IsAnchored`
stays `false` | first and last item (unverified) |
| iOS legacy handler (opt-in) | not implemented | first and last item |
| Horizontal layouts | not anchored | first and last item |

#### Tests

- **Unit tests** (`Controls.Core.UnitTests`): 108/108 pass on .NET 12,
after merging `main` at dfca8ad37c. The whole project passes too: 7033
tests, 30 skipped.
  - 83 tracker tests spell out the rules for both edges.
  - 25 cover the API:
    - `AnchorMode` and `IsAnchored`;
    - how `ScrollToStart` and `ScrollToEnd` reach the handler;
- their `ScrollTo` fallback, grouped lists, and calls without a handler,
which don't read `ItemsSource`.
- **Device tests** (`CollectionViewTests.ScrollAnchor.cs`): 145 cases
run on Android, 142 on iOS and 144 on Mac Catalyst, as some are
platform-specific. They last ran locally on .NET 11, before the merge of
`main` at dfca8ad37c moved the branch to .NET 12; CI runs them on .NET
12. Each review fix was first reproduced without the fix, by a device
test, a unit test, or a scripted check on Mac Catalyst. In the latest
rounds, on the Android emulator unless noted:
- A new test of 2 cases turns a horizontal `End` list vertical and
requests `ScrollTo(10)` right after it, or right before it, in the same
update. Before the change, the case with the request after the switch
failed on Android: item 10 never came into view, as the anchor started
over at its first look after the layout and dropped the request. Both
cases pass on Android and Mac Catalyst.
- Merging `main` (#40577): with #39491 and #39493, `KeepItemsInView`,
the default `ItemsUpdatingScrollMode`, scrolls a list that doesn't
follow an edge to its first item as items are added. 5 tests (9 cases)
check that only the anchor moves such a list, and 8 of those cases
failed with the list at its first item: 7 on Android, and 1 of the 2 Mac
Catalyst cases of another, whose other case passed only because the list
went to its start, away from its end. The 5 tests now set
`KeepScrollOffset`, and pass.
- After the merge, the Mac Catalyst device-test app crashed 3 times in 3
runs (SIGBUS and SIGSEGV in UIKit's observation tracking, during
layout). The first managed failure was an `NSInvalidArgumentException`
("attempt to insert nil object") from `InvalidateItems` in
`ItemsViewController2.InvalidateLayoutIfItemsMeasureChanged`, inside the
layout an animated `ScrollToEnd` forced. The test helpers
`GetItemHeight` and `GetGroupedItemHeight`, called from a `Scrolled`
handler in that layout, disposed the index path they looked up: the
managed peer of UIKit's equal index path, which the handler held for
`InvalidateItems`. They no longer dispose it; the class then passes. The
pre-merge head passed on the same machine (macOS 27.2.1), so the merged
layout timing exposed it.
- On Android, a new test opens an `End` list whose first row is 1000
high and whose other 110 rows are 3 high, so at the end the first row
sits just above the view, measured only by RecyclerView's estimate. Code
then scrolls the native view up 100, which lays that row out. Before the
change, the list was pulled back to its end: the first row at -2455 px
right after the scroll, then row 12 at the top. Two new tracker tests (3
cases) cover `MoveOrigin`; all 3 fail with it doing nothing.
- On Android, a new test of 2 cases (`None`, `Start`) has a
`ScrollTo(5)` that doesn't animate stop an animated scroll on a
horizontal list, and the app changes `AnchorMode` to `End` from the
`RemainingItemsThresholdReached` that stopping raises. Before the
change, both failed: the mode change dropped the jump, and item 5 never
came into view.
- On iOS and Mac Catalyst, a new test of 2 cases calls an animated
`ScrollToStart` or `ScrollToEnd` on a list at that edge, and then has
code scroll the native view 200 away from it. Before the change, both
failed on Mac Catalyst, with the list pulled back to the edge.
- On iOS and Mac Catalyst, a new test of 4 cases (`None` or `End`, the
scroll animated or not) has code scroll the native view to 100 short of
the end right after an animated `ScrollToStart` from the end. Before the
change, both animated cases failed on Mac Catalyst: the jump to the
start overrode that scroll, and the list never got to 100 short of its
end. The others passed before too: UIKit reports the end of an animation
that a scroll without animating stops before it applies that scroll. The
test allows for UIKit moving the end further away as it measures the
rows the scroll brought into view, which once left the list 230 short of
the end, with the offset where the scroll put it.
- That test's animated `End` case also failed in 5 or 6 of 10 repeats,
for a race this round fixes: a row UIKit measured while the view was
still within 8 units of the end took the view back there. A new test
grows the last row as code starts animating the native view of an `End`
list 100 short of the end. Before the change, the list was back at the
end and still anchored in each of 3 tries on Mac Catalyst. Now it ends
where a list without anchoring does: 130 short of the end on macOS 27,
as UIKit measures the rows above again. All 10 repeats of the race pass.
CI's Mac Catalyst run on macOS 26 ended that test 360 short of the end,
where it had checked for at most 300: UIKit there measures the rows
above differently, and iOS 26 and macOS 15 passed it. The anchor only
ever scrolls a list that follows its end to the end, so the test now
checks that the list stays away from both edges (less than half the
scroll range from the end) rather than how far UIKit takes the end.
- The test of a `ScrollToEnd` from `Scrolled` as `ScrollToStart` goes
the rest of the way used to fake UIKit's report that the animation
ended, right after the request, with the list still at the end. It now
lets UIKit stop the animation short of the start: 200 short on Mac
Catalyst, as rows are estimated at 30 and measure 40.
- A new Android test of 4 cases (`ScrollToStart` or `ScrollToEnd`, with
a matching anchor or none) stops an animated scroll past the
`RemainingItemsThresholdReached` threshold with a `ScrollTo(20)` that
doesn't animate, and calls `ScrollToStart` or `ScrollToEnd` from that
event. Before the change, both cases without an anchor failed: the older
`ScrollTo` won, with row 13 at the top, or the end out of view. With a
matching anchor they passed before too, as the anchor's reset takes the
view to its edge.
- On iOS and Mac Catalyst, a new test of 2 cases stops an animated
`ScrollToEnd` on its way with a native scroll back to the start, without
animating, or animated as a status-bar tap does. Before the change, both
failed on the iPhone 18 Pro simulator: the list stayed at its start, but
`IsAnchored` stayed `true`.
- On iOS and Mac Catalyst, a new test of 2 cases (`End`, `MakeVisible`)
makes an animated `ScrollTo` in a grouped list that measures all its
items while the list is out of its window, and then scrolls the native
view back toward the start, animated. Before the change, both failed on
the iPhone 18 Pro simulator: as that animation ended, the list scrolled
back to the item, 1006 from the start (878 when it first showed the
item). UIKit stops that animation short of the start, as it measures the
rows above that the jump skipped, so the test checks that the list
doesn't go back to the item rather than that it reaches the start.
- A new test of 2 cases calls `ScrollToEnd(false)` and then an animated
`ScrollToStart` on a horizontal list at its start, and the reverse.
Before the change, both failed on Android, with the list at the edge it
jumped to. iOS and Mac Catalyst passed before the change too.
- A new test of 4 cases (every `AnchorMode`) calls `ScrollToEnd(false)`
and then an animated `ScrollTo(0)` on a list at its start. Before the
change, all 4 failed on Android with the list at the end (row 32 at the
top), including End and Start | End, where the jump was the anchor's.
iOS and Mac Catalyst passed before the change too.
- On iOS and Mac Catalyst, a new test insets the bottom of an End list
by 300 and scrolls the native view up 200 outside a layout pass, as the
keyboard manager does. The anchor judges that as layout and keeps the
end in view. With the `IsResized` veto removed, it failed on the iPhone
18 Pro simulator: 530 from the end, no longer following it.
- On iOS and Mac Catalyst, a new test has code scroll the native view up
200 right after UIKit reports that an animated scroll ended, before the
layout pass that follows. UIKit reports the end of a drag, a
deceleration or an animated scroll before that pass, and the anchor took
a scroll in between for the end of the one that ended. Before the
change, the list was pulled back to its end on the iPhone 18 Pro
simulator, 0 from the end. A new tracker test covers `IsResized`: an
offset move that comes with a size change is still judged as layout.
- On Mac Catalyst, back at the end of an End list after a `ScrollTo(0)`
that doesn't animate, through native scrolls that aren't drags, a new
test shrinks the last item. Before the change, the restore that
`ScrollTo` armed took the list back to its first item: 30 from the
start, 1100 from the end, not anchored.
- A native scroll up 200 from a scroll listener as a short fling goes
idle, before the anchor's posted look, has a new test. Before the
change, the list was pulled back to its end. Two new tracker tests cover
it: the original code took the view back to the edge, and gating the
gesture-end exemption alone stopped following for a scroll toward the
end.
- Code scrolling the native view up 200 from the GlobalLayout callback
after items are appended, before the anchor's posted jump to the new end
lands, has a new test. Before the change, the list jumped from row 27,
where the scroll left it, to the end at row 52. It passes now, and with
`DeferCorrection` resetting the tracker as before, the 2 new tracker
tests of a scroll away fail.
- An animated `ScrollTo` to the first item, from the end of a list that
follows only its end, has a new test of 2 cases: the last row grows, or
an item is added, once the list is laid out for the request and before
the animation moves it. Before the change, both failed with the list
back at the end: 1040 and 1120 from the start on the iPhone 18 Pro
simulator, 1170 and 1200 on Mac Catalyst. Android needed no change for
them. A new test of an animated `ScrollTo` to where the last item
already is failed on Android before the change: once the last row grew,
the list had stopped following, 80 short of the end. All 3 cases pass on
Android, iOS and Mac Catalyst now.
- CI's Mac Catalyst run on macOS 26 left an animated `ScrollToStart`
from the end of a list that follows only its end at the end, 1220 from
the start, in one of its two runs. A new test of 2 cases grows the last
row, or adds an item, once the list is laid out for the request and
before the animation moves it. Before the change, both failed on the
iPhone 18 Pro simulator and on Mac Catalyst, with the list back at the
end: 1220 from the start for the grown row on Mac Catalyst, as in CI.
Both pass on Android, iOS and Mac Catalyst now. Android needed no
change.
- A throwaway probe on the iPhone 18 Pro simulator showed that UIKit
reports the end of a scroll animation in every case it tried: one that
finishes, one a scroll stops, the view leaving its window, an inset,
content size or visibility change. A view that isn't in a window doesn't
animate: UIKit scrolls it and reports the end before the call returns. A
new iOS and Mac Catalyst test of 2 cases takes the list out of its
window for an animated `ScrollToStart` or `ScrollToEnd`. Before the
change, the `ScrollToStart` case failed on the iPhone 18 Pro simulator:
back at its end, the list didn't follow a new item, 40 short of the end.
Both pass on iOS and Mac Catalyst now.
- An animated `ScrollToStart` or `ScrollToEnd` right after one to the
other edge that doesn't animate, on a list settled at the edge the
animated one goes to, has a new test of 16 cases: every `AnchorMode`,
both edges, and with or without a header and footer. Before the change,
6 failed. The animated `ScrollToStart` that the view doesn't follow
(`AnchorMode` `None` or `End`) left the list at the end. With rows of
one height and no header or footer, an anchored `ScrollToStart` or
`ScrollToEnd` left it at the other edge too. All 16 pass on Android, iOS
and Mac Catalyst now.
- With the data-item check removed, a `ScrollTo` that doesn't animate,
for the footer's index (`items.Count`) or the header's (-1), right after
`ScrollToEnd(false)` cancelled the adjustment that finishes it: the list
stopped 299.8 and 350.1 short of the end.
- iPhone 18 Pro simulator: without the handover, turning `AnchorMode`
off during an animated `ScrollToEnd` or `ScrollToStart` to the edge the
list followed left it 230 short of the end and 130 from the start.
Android reached the edge either way.
- The check that scrolling the native view away as an item is added
stops following the end now runs on iOS and Mac Catalyst too. It passes
there unchanged: UIKit resizes the content as the item is inserted,
which the anchor looks at before the scroll.
- With the request check across the stop removed, a `ScrollTo` requested
from the `RemainingItemsThresholdReached` that stopping a scroll raises
lost to the edge the list went to: for a mode change, and for
`ScrollToEnd` and `ScrollToStart` that don't animate. Without stopping
the view before the jump, all four `ScrollToEnd` and `ScrollToStart`
cases failed, with a matching anchor and without one.
- With the horizontal check removed, both cases of the new test of a
mode change during an animated `ScrollTo` on a horizontal list failed.
On Android the scroll stopped and never reached the item. On the iPhone
18 Pro simulator it stopped too, and UIKit then put the view at the item
in a single jump at the next layout, so the test also checks that the
scroll keeps animating.
- Without the change to the animated `ScrollToEnd`, both cases of its
new test failed, with the last row grown before the request or after it:
the footer stayed out of view.
- CI's Mac Catalyst run on macOS 26 ended the case that grows the row
after the request 50 short of the end, in one of its two runs. iOS and
Mac Catalyst lay the view out as `ScrollToEnd` is called, and follow a
row grown after it only while UIKit measures the rows the scroll brought
into view (see open question 11), so that case runs on Android only.
Both cases check that the view reached the end of the grown row, as the
test of a row measured in a later layout does.
- With `main`'s lookup for `ScrollTo(index, groupIndex)` restored, both
of the new direct calls failed: one threw `ArgumentOutOfRangeException`
for a group without a header, and the other scrolled to the equal item
of the first group.
- With the anchor's stop left as it was, the case of a mode change right
after an animated `ScrollToEnd` failed: the scroll waiting for the
layout still took the list to the end.
- Android API 37 emulator, after merging `main` at bca4740888 (.NET 11):
all 300 `CollectionViewTests` pass, with 1 skip that predates this PR.
- Mac Catalyst (macOS 27.2.1), after merging `main` at bca4740888 (.NET
11): all 209 `CollectionViewTests` pass, with 4 skips that predate this
PR. The latest local iOS run (iOS 27.2) is of an earlier head: all 170
passed. CI's iOS stages, on macOS 15 and macOS 26 hosts, passed every
anchor test on 42c1a3060d. Each has 4 skips that predate this PR. The
Xcode 27.2 SDK requires a scene manifest in the device-test app
(MT7199), so these ran with one added locally. It isn't part of this PR.
- The horizontal cases wait until the list is laid out before they
scroll: before that, a list is at both of its edges, and they passed on
iOS without scrolling.
- CI's device tests on iOS 26 and macOS 26 found failures that iOS 27
and macOS 27 don't show. This head addresses them:
- UIKit moved the offset before it updated the content size, while it
updated the view for a new layout (a replaced header or footer) or for
removed items. The controller now brackets those updates as layout.
- Rows measured during an animated `ScrollToStart` moved the offset away
from the start before any size change was reported. An animated scroll
to an edge now follows that edge until it gets there.
- A one-shot `ScrollToEnd` that doesn't animate finished in the layout
passes it forced, before UIKit measured the rows there. It now finishes
only in a layout pass UIKit runs on its own.

The replaced header and the one-shot `ScrollToEnd` failed locally too,
and pass now. New unit tests cover following an edge on the way there,
and a new device test covers the one-shot `ScrollToEnd`. Only CI can
confirm the fixes on iOS 26 and macOS 26.
- **UI tests** (`CollectionViewAnchorModeEnd`, 3 tests). They cover
following added and growing items, scrolling away and back, and
`ScrollTo` away from the end followed by `ScrollToEnd`. The growing-item
test waits until the last message has grown before it checks that the
footer is in view. Their waits find a row again when the list recycled
it between finding it and reading its geometry.
  - 3/3 on an iPhone 18 Pro simulator (iOS 27.2) with real touch.
  - 3/3 on an Android API 37 emulator.
- **Mac Catalyst and the iPhone 18 Pro simulator:** local scripted
checks of the scenarios above all pass. They include:
  - 32/32 repeated one-shot `ScrollToEnd` runs on each;
- a `ScrollTo` from `Scrolled` or from `IsAnchored` during
`ScrollToEnd`, or from `Scrolled` as `ItemsSource` is replaced;
- a mode change during an animated `ScrollTo`, including before its
first frame;
  - `KeepLastItemInView` with `Start`;
- the restore armed by a `ScrollTo` that doesn't animate. With the two
clears removed, the list goes back to that item.
- **Not run locally:**
- Catalyst UI tests: on this machine Appium loses the app at launch for
any test page, including existing ones.
  - iOS 26 and macOS 26, which only CI has.

<details>
<summary>Commands</summary>

```bash
# Unit tests: 108 passed
dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj \
  --filter "FullyQualifiedName~ScrollAnchorTrackerTests|FullyQualifiedName~StructuredItemsViewAnchorModeTests"

# UI tests, with the HostApp installed on the device: 3 passed on each
DEVICE_UDID=<simulator udid> dotnet test src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj \
  --filter "FullyQualifiedName~CollectionViewAnchorModeEnd"
DEVICE_UDID=emulator-5554 dotnet test src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj \
  --filter "FullyQualifiedName~CollectionViewAnchorModeEnd"

# Android device tests: 300 passed, 1 skipped (on .NET 11, before the merge that moved the branch to .NET 12)
EmbedAssembliesIntoApk=true pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls \
  -Platform android -Configuration Debug -IncludeClasses "Microsoft.Maui.DeviceTests.CollectionViewTests" -BuildOnly
dotnet xharness android test \
  --app artifacts/bin/Controls.DeviceTests/Debug/net12.0-android/com.microsoft.maui.controls.devicetests-Signed.apk \
  --package-name com.microsoft.maui.controls.devicetests \
  --instrumentation com.microsoft.maui.controls.devicetests.TestInstrumentation \
  --device-id emulator-5554 -o artifacts/log/anchor-android --timeout 00:45:00

# iOS device tests (with a local scene manifest): 170 passed, 4 skipped, on an earlier head. Mac Catalyst: 209 passed,
# 4 skipped. Both ran on .NET 11. For Mac Catalyst, use -f net12.0-maccatalyst -r maccatalyst-arm64 and --target maccatalyst.
dotnet build src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj -c Debug -f net12.0-ios -r iossimulator-arm64
dotnet xharness apple test \
  --app artifacts/bin/Controls.DeviceTests/Debug/net12.0-ios/iossimulator-arm64/Microsoft.Maui.Controls.DeviceTests.app \
  --target ios-simulator-64_27.2 --device <simulator udid> -o artifacts/log/anchor-ios --timeout 00:40:00 \
  --set-env=NUNIT_SKIPPED_CLASSES=Microsoft.Maui.DeviceTests.CollectionViewTests
```

</details>

#### Open questions for API review

1. **Names.** `ScrollAnchorMode` or `ItemsAnchorMode`? I chose
`ScrollAnchorMode` so a vertical `ScrollView` can reuse it later; the
same tracker already works for one. `AnchorMode` matches Blazor, but it
sits next to `VisualElement.AnchorX` and `AnchorY`, which are transform
anchors.
2. **Default.** It's `None`, so existing apps don't change. Blazor's
default is `Start`.
3. **`IsAnchored`** is a `bool` for either edge. Should it say which
edge the view follows, for `Start | End`?
4. **Changing `AnchorMode`** shows the edge it selects. Blazor doesn't
scroll when the mode changes.
5. **Threshold.** The 8-unit threshold is fixed and internal; Blazor
uses 2 px.
6. **Windows:** `AnchorMode` isn't implemented, because it can't be
verified on a Mac. WinUI's `VerticalAnchorRatio` may fit.
`ScrollToStart` and `ScrollToEnd` scroll to the first and last item the
default handler shows, but that's unverified too: the WinUI XAML
compiler doesn't run on macOS, so it hasn't even been compiled here.
7. **Horizontal layouts and right-to-left** aren't anchored.
8. **Snap points.** With mandatory snap points, `ScrollToEnd` ends at
the nearest snap point, as `ScrollTo` does. On Android, `ScrollToStart`
and `ScrollToEnd` drop the item a `MandatorySingle` fling snapped to, as
`ScrollTo` does, so the snap doesn't take the view back to it. Anchoring
isn't designed for snapping lists.
9. **Mac Catalyst's silent offset clamp (#34271).** It doesn't reproduce
on this machine, through a Picker, minimizing and restoring, or a
resize. The anchor still hears of an offset change only KVO reports, and
follows its edge again: a device test simulates one by moving the
layer's bounds with manual KVO notifications.
10. **Overlap with `ItemsUpdatingScrollMode`** (#39491 and #39493, now
in `main`). While the view follows an edge, the anchor keeps it there:
`AdjustScrollForItemUpdate` on Android and
`FinalizeCollectionViewUpdates` on iOS and Mac Catalyst return early.
Otherwise `ItemsUpdatingScrollMode` applies as before. Its default,
`KeepItemsInView`, scrolls the list to its first item as items are
added, so an `End` list the user scrolled away from jumps to its first
item unless the app sets `KeepScrollOffset`. Should `AnchorMode` keep
the offset while the view doesn't follow an edge?
11. **One-shot `ScrollToEnd` without End anchoring** scrolls once. On
Mac Catalyst with accessibility active, UIKit measures rows above the
view 100 to 300 ms after a scroll without keeping the content in place,
which can leave the view 80 to 100 short of the end. After a row
resizes, UIKit also lays offscreen rows and the header out at their
estimated size and measures them again later, which can leave it 30
short. Both are Items2 behavior that predates this PR, and the device
tests allow for them. Should a one-shot `ScrollToEnd` hold the end until
something else scrolls the view, as UIKit holds a `scrollToItem` target?
Or should Items2 keep the content in view in place as UIKit measures
rows above it, for every scroll?
12. **Turning anchoring off** doesn't stop a scroll under way; a review
suggested it should. It isn't a scroll, and stopping one would make
`ScrollTo(item, animate: true); AnchorMode = None;` drop the scroll
while the reverse order keeps it. An animated `ScrollToStart` or
`ScrollToEnd` to the edge the view followed still goes all the way
there. A change to `Start` or `End` does stop it, as it scrolls to that
edge, except on a horizontal layout, which isn't anchored.

### 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. -->

N/A: this is a new feature, and it doesn't fully fix any open issue.
Related:

- #35802 (KeepLastItemInView does nothing on .NET 10 iOS and Android):
not fixed here. `AnchorMode="End"` is the alternative for chats.
- #12036, #29153 (grouped lists): `AnchorMode="End"` follows grouped
lists. This PR doesn't change `KeepLastItemInView`; `main` has since
fixed #29153 (#39491, #39493).
- #29420 (CarouselView): out of scope, because CarouselView isn't a
`StructuredItemsView`.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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

partner/syncfusion Issues / PR's with Syncfusion collaboration s/agent-review-in-progress AI review is currently running for this PR

Projects

None yet

3 participants