Skip to content

[iOS/MacCatalyst] Keep CollectionView following its edge when UIKit animates the view back as it lays it out - #40854

Merged
kubaflo merged 1 commit into
mainfrom
simonrozsival-catalyst-scroll-anchor-shrink-flake
Nov 30, 2026
Merged

kubaflo merged 1 commit into
mainfrom
simonrozsival-catalyst-scroll-anchor-shrink-flake

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 06dd7c47b0c2d9b0c41cb5aafc4e57fc09571b75

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ The new test fails without the fix in every local run (Mac Catalyst 40/40, iOS 27 simulator 42/42) and passes with it (iOS 27 42/42, Mac Catalyst 39/40; the one miss timed out in the harness window setup before the test body ran).
↑ Whole CollectionView device-test family with the fix: Mac Catalyst 422 passed, 0 failed, 8 skipped in two runs; iOS 27 418 passed, 0 failed, 8 skipped.
↑ Acts only on a scroll animation UIKit starts inside a layout pass while the view follows an edge; animations the app or the anchor started, drags and decelerations are excluded. No public API change. Merges cleanly with #40828.
↓ No PR CI: the device-test pipelines are disabled. The local host runs macOS 26.7.3; CI runs macOS 27.2.
Diagnosis confidence 8.5/10 ↑ Native stack of the animation start: -[UICollectionView layoutSubviews] → _setContentSize:skipContentOffsetAdjustment: → performWhileAnimatingAutomaticContentOffsetAdjustments: → _adjustContentOffsetIfNecessary → setContentOffset:animated:YES (850 → 760).
↑ Anchor trace: ScrollAnimating turns true in that layout pass, the anchor counts it as user scrolling, and it switches from End to None once the re-targeted animation is 10 points above the end.
↓ When UIKit animates this adjustment rather than applying it at once is inferred from private method names.
Evidence fit 4/10 ↑ Same signature as the Mac Catalyst CI failures in builds 1704369 and 1704494: the list stops following its end and stays a fixed distance above it (370 in both).
↓ The flaky test's own shrink step doesn't start this animation on macOS 26.7.3 or the iOS 27 simulator (100+ local runs pass before and after the fix), so it isn't confirmed that macOS 27 takes this path; CI is disabled.

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!

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

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

This investigates the intermittent Mac Catalyst device-test failure [CollectionView] Back at the end after a ScrollTo away, the list keeps the end in view as the last item shrinks on main ("Following the end, the list should keep the end in view as the last item shrinks. Distance to the end: 370."). It fixes a deterministic ScrollAnchorMode (#40211) defect on iOS and Mac Catalyst that leaves the list in the same failed state.

Root cause. When the content of a UICollectionView shrinks under its content offset during a layout pass, UIKit animates the view back within the content. Native stack captured locally on Mac Catalyst:

-[UICollectionView setContentOffset:animated:]       animated: YES, 850 → 760
-[UICollectionView _applyAutomaticAdjustedContentOffset:]
-[UIScrollView _adjustContentOffsetIfNecessary]
-[UIScrollView setContentSize:]
-[UICollectionView setContentSize:]
-[UIScrollView performWhileAnimatingAutomaticContentOffsetAdjustments:]
-[UICollectionView _setContentSize:skipContentOffsetAdjustment:]
-[UICollectionView _updateVisibleCellsNow:]
-[UICollectionView layoutSubviews]

CollectionViewScrollAnchor treats every scroll animation it didn't start as a fling (ScrollAnimating), and stops correcting until it ends. On its way, UIKit measures the rows the animation brings into view and re-targets it, so the view ends up above where the end settles. The anchor sees the view move more than its threshold away from the end and stops following it (End → None), and the view stays there.

This happens whenever rows are shorter than UIKit's 30-point estimate (LayoutFactory2 uses NSCollectionLayoutDimension.CreateEstimated(30)). The anchor goes to the end as estimated, UIKit measures the rows there shorter, the content shrinks under the view, and UIKit animates back.

Fix. CollectionViewScrollAnchor.LayoutStarting now notes whether a scroll animation is running when an outermost layout pass starts. In LayoutFinished, if one is running that wasn't before, and neither the anchor nor the app started one (no edge animation, no animated request, no drag or deceleration), UIKit started it while laying the view out. A view that follows an edge stops it where it starts with SetContentOffset(ContentOffset, false), the idiom the controller already uses to stop animations. The usual post-layout look then scrolls to the edge. Views that don't follow an edge keep UIKit's animation. The three LayoutStarting call sites in ItemsViewController2 now pass the collection view.

Regression test. AnchorMode End shows and follows the end of rows shorter than UIKit estimates them (iOS and Mac Catalyst): 40 rows of 20 points must open at their end, and the list must keep following its end when 20 more arrive.

Local run Without the fix With the fix
Mac Catalyst (macOS 26.7.3), new test ×20 per navigation variant 40/40 failed: 32 didn't open at the end (45 to 89.5 above it), 8 lost it after the batch (up to 486 above) 39/40 passed; the other timed out in the harness window setup (OnLoadedAsync) before the test body ran
iOS 27.0 simulator, new test ×21 per navigation variant 42/42 failed: 40 didn't open at the end (40 above it), 2 lost it after the batch 42/42 passed
Mac Catalyst, whole CollectionView family (both variants) — 422 passed, 0 failed, 8 skipped (two runs)
iOS 27.0 simulator, whole CollectionView family — 418 passed, 0 failed, 8 skipped

The repeated runs used a temporary local theory that called the new test; it isn't part of this PR. The flaky test also passed 40/40 locally with the fix, and its assertions are unchanged.

Relationship to the Mac Catalyst CI failure. Both observed failures end with the list no longer following its end and a stable 370 points above it: build 1704369 on main 9c4919b856 ([NavigationViewHandler]) and build 1704494 ([NavigationRenderer]). That's the state this defect leaves the view in. Locally, though, the flaky test's shrink step doesn't take this path. On macOS 26.7.3 and on the iOS 27 simulator, UIKit re-estimates the rows above and moves the offset in that layout pass before it shrinks the content, so it never animates. More than 100 local runs of that test passed, with and without this change, including in the full family. CI runs macOS 27.2, which I couldn't run locally. So this PR fixes a real, deterministic anchor defect with the same failure signature, and it's the most likely explanation I found, but it doesn't prove that the macOS 27 run took this path.

Other findings, not changed here:

  • With macOS keyboard navigation enabled, the focus engine asks the collection view for preferredFocusedView. UIKit then sizes that cell outside a layout pass (_endReusableViewCreationAndSelfSizingOutsideVisibleCellsUpdate), and applies the compositional layout's content-offset adjustment at once. It reports the move to scrollViewDidScroll before it updates the content size, and the anchor judges it as a scroll. With rows taller than the estimate, as in the flaky test, the move is toward the end and harmless. With shorter rows it briefly un-anchors the list. A possible follow-up is to treat offset changes made inside CustomUICollectionViewCompositionalLayout.InvalidateLayout(context) as layout.
  • [iOS/MacCatalyst] Arm CollectionView anchor animations before reentrant UIKit callbacks #40828 changes the animated ScrollToStart/ScrollToEnd branches; this PR changes LayoutStarting/LayoutFinished. Their hunks don't overlap, and a trial merge is clean. [iOS/MacCatalyst] Preserve newer CollectionView scroll completion during reentrant scrolls #40817 is unaffected.

CI. maui-pr, maui-pr-uitests and maui-pr-devicetests have been disabled since 2026-11-29 23:22 UTC, so CI hasn't run on this PR. It's pending until the pipelines are re-enabled; the validation above is local.

Validation, with the pinned SDK 12.0.100-alpha.1.26523.103 and Xcode 27.2 (hence -SkipXcodeVersionCheck):

pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform maccatalyst \
  -DotnetPath "$PWD/.dotnet/dotnet" -SkipXcodeVersionCheck \
  -IncludeClasses Microsoft.Maui.DeviceTests.CollectionViewTests,Microsoft.Maui.DeviceTests.CollectionViewNavigationHandlerTests
# passed: 422 passed, 0 failed, 8 skipped (430 total), in two runs

pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform ios -iOSVersion 27 \
  -DotnetPath "$PWD/.dotnet/dotnet" -SkipXcodeVersionCheck \
  -IncludeClasses Microsoft.Maui.DeviceTests.CollectionViewTests,Microsoft.Maui.DeviceTests.CollectionViewNavigationHandlerTests
# passed: 418 passed, 0 failed, 8 skipped (426 total)

pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform maccatalyst \
  -DotnetPath "$PWD/.dotnet/dotnet" -SkipXcodeVersionCheck \
  -IncludeClasses Microsoft.Maui.DeviceTests.CollectionViewTests,Microsoft.Maui.DeviceTests.CollectionViewNavigationHandlerTests \
  -IncludeMethods AnchorModeEndShowsAndFollowsTheEndOfRowsShorterThanEstimated
# without the product change: 0 passed, 2 failed (distances 67.5 and 490); with it: 2 passed

dotnet format whitespace Microsoft.Maui.sln --no-restore --exclude Templates/src --include <the three changed files>
# passed, no changes

Issues Fixed

No standalone issue. Related to #40211 (ScrollAnchorMode), the intermittent Mac Catalyst failure above, #40828 and #40817.

Let AI finish this PR

  • Let the MAUI agent address review feedback and fix remaining issues on this PR. Maintainers still decide whether it is merged. For PRs from forks, keep "Allow edits by maintainers" on so the agent can push to your branch; otherwise it opens a follow-up PR that keeps your commits.

…nimates the view back as it lays it out

When the content of a UICollectionView shrinks under its content offset
during a layout pass, UIKit animates the view back within the content:
-[UICollectionView _setContentSize:skipContentOffsetAdjustment:] wraps
the content size update in performWhileAnimatingAutomaticContentOffset-
Adjustments:, and -[UIScrollView _adjustContentOffsetIfNecessary] then
calls setContentOffset:animated:YES.

The scroll anchor took every scroll animation it didn't start for a
fling: it stopped correcting, and, as UIKit measured the rows the
animation brought into view and re-targeted it, it judged the view to
have moved away from the edge and stopped following it. With rows
shorter than UIKit's 30-point estimate, a list with AnchorMode End
mostly failed to open at its end, and otherwise lost it when a batch of
such rows arrived.

The anchor now notes whether a scroll animation is running when a
layout pass starts. If one runs when the pass is done that didn't when
it started, and neither the app nor the anchor started one, UIKit
started it as it laid the view out: a view that follows an edge stops
it where it starts and goes to the edge, as for any other layout change.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 30, 2026 10:13
@github-actions

This comment has been minimized.

@simonrozsival

Copy link
Copy Markdown
Member Author

@kubaflo, could you review this? It's in the same scroll-anchor family as #40817 and #40828. It touches only LayoutStarting/LayoutFinished in CollectionViewScrollAnchor, and a trial merge with #40828 is clean.

The evidence, in short:

  • Deterministic repro, fixed here. With AnchorMode End and rows shorter than UIKit's 30-point estimate, the list can't reliably open at, or keep, its end. Without the fix the new test failed in every local run: Mac Catalyst 40/40, iOS 27 simulator 42/42. With it, iOS 27 passed 42/42 and Mac Catalyst 39/40 (the miss was a harness window-setup timeout before the test body ran).
  • Mechanism. When the content shrinks under the offset during a layout pass, UIKit animates the view back: -[UICollectionView _setContentSize:skipContentOffsetAdjustment:] → performWhileAnimatingAutomaticContentOffsetAdjustments: → _adjustContentOffsetIfNecessary → setContentOffset:animated:YES. The anchor took that animation for a fling. UIKit re-targeted the animation as it measured rows, and the anchor stopped following the end (End → None).
  • Link to the flaky Mac Catalyst test. "Distance to the end: 370" in builds 1704369 and 1704494 is the state this leaves the list in. I couldn't reproduce that test's failure locally, though: 100+ passes on macOS 26.7.3 and the iOS 27 simulator, where its shrink step doesn't start the animation. So the macOS 27 path is unconfirmed, and CI is disabled for now.
  • No regressions locally. The whole CollectionView family passes with the fix: Mac Catalyst 422/0/8 (two runs), iOS 27 418/0/8.

One more finding, not changed here: with macOS keyboard navigation on, the focus engine's preferredFocusedView makes UIKit size a cell outside a layout pass and report the offset adjustment to scrollViewDidScroll, which the anchor also judges as a scroll. Details are in the PR description.

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 scroll-anchor logic can cancel deliberate native scroll animations during layout even without content shrinkage, requiring a narrower cancellation condition and a regression test.

1 open issue
What changed in this PR

This PR updates the iOS/Mac Catalyst CollectionView handler to preserve edge anchoring when UIKit starts an automatic scroll animation during layout.

Changes:

  • Tracks animation state at the start of layout and stops newly detected animations under edge-following conditions.
  • Passes the collection view into all three layout-start hooks.
  • Adds a device regression test for opening at—and continuing to follow—the end of rows shorter than UIKit’s estimates.
File Description
src/​Controls/​tests/​DeviceTests/​Elements/​CollectionView/​CollectionViewTests.ScrollAnchor.cs Tests end anchoring with short rows and appended items.
src/​Controls/​src/​Core/​Handlers/​Items2/​iOS/​ItemsViewController2.cs Supplies the native view to layout-start tracking.
src/​Controls/​src/​Core/​Handlers/​Items2/​iOS/​CollectionViewScrollAnchor.cs Detects and stops animations begun during layout while following an edge.

Review effort: Balanced

Comment on lines +135 to +138
if (!_animatingBeforeLayout && isVertical && _tracker.IsAnchored && _edgeAnimation is null && !_animatingRequest
&& !collectionView.Dragging && !collectionView.Decelerating && IsScrollAnimating(collectionView))
{
ApplyOffset(collectionView, collectionView.ContentOffset.Y);
@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Selected Tests

@kubaflo — AI-selected UI tests and device tests (GPT-6.2 Sol + MAI Code 2) for commit 06dd7c47.

Result NOT QUEUED Platforms iOS, MacCatalyst Tests 8 UI, 2 device Commit 06dd7c47


🧪 Test selection — click to expand
Suite Result Selected Build
UI tests ❌ not queued 8 of 77 categories —
Device tests ❌ not queued 2 of 105 units —
🧪 UI tests — CarouselView, CollectionView1, CollectionView2, CollectionView3 +4 on iOS, MacCatalyst

❌ Could not queue maui-pr-uitests: Azure Pipelines did not start maui-pr-uitests for the dispatch branch run-tests/pr40854-46406207908 within 10 minutes. Comment /review run-tests again, or use /azp run maui-pr-uitests for the full suite.

GPT-6.2 Sol: Run CollectionView and CarouselView UI tests on iOS and Mac Catalyst for the Items2 scroll-anchor change.
MAI Code 2: iOS and Mac Catalyst CollectionView2 scroll-anchor fix; runs CollectionView and CarouselView coverage on both platforms.

🧪 Running — 8 categories on iOS, MacCatalyst

Platform Categories
iOS CarouselView, CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7
MacCatalyst CarouselView, CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7
🧪 Device tests — Controls.CarouselView, Controls.CollectionView on iOS, MacCatalyst

❌ Could not queue maui-pr-devicetests: Azure Pipelines did not start maui-pr-devicetests for the dispatch branch run-devicetests/pr40854-46406207908 within 10 minutes. Comment /review run-tests again, or use /azp run maui-pr-devicetests for the full suite.

GPT-6.2 Sol: Run CollectionView and CarouselView device tests on iOS and Mac Catalyst, including the new scroll-anchor regression.
MAI Code 2: Run CollectionView and coupled CarouselView device tests on iOS and Mac Catalyst for the Items2 anchor-animation fix.

🧪 Running — 2 categories on iOS, MacCatalyst

Platform Categories
iOS Controls.CarouselView, Controls.CollectionView
MacCatalyst Controls.CarouselView, Controls.CollectionView
⏭️ Skipped — what neither suite runs

UI tests — 69 categories, 2 platforms

Platforms not run: Android, Windows

Categories not run: Accessibility, ActionSheet, ActivityIndicator, Animation, AppLinks, Border, BoxView, Brush, Button, Cells, CheckBox, ContextActions, CustomRenderers, DatePicker, Dispatcher, DisplayAlert, DisplayPrompt, DragAndDrop, Entry, Editor, Effects, Essentials, FlyoutPage, Focus, Fonts, Frame, Gestures, GraphicsView, Image, ImageButton, IndicatorView, InputTransparent, IsEnabled, IsVisible, Label, Layout, Lifecycle, ManualReview, Maps, Navigation, Page, Performance, Picker, ProgressBar, RadioButton, RefreshView, SafeAreaEdges, Shadow, ScrollView, SearchBar, Shape, Slider, SoftInput, Stepper, Switch, SwipeView, Shell1, Shell2, TabbedPage, TableView, TimePicker, TitleView, ToolbarItem, Triggers, ViewBaseTests, VisualStateManager, Window, WebView, Material3

Each skipped platform and category is listed as a maui-pr-uitests (skipped) … status on this commit. Use /azp run maui-pr-uitests for the full suite.

Device tests — 103 categories, 2 platforms

Platforms not run: Android, Windows

Categories not run: Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CheckBox, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay, Graphics, Essentials, BlazorWebView

Each skipped platform and project is listed as a maui-pr-devicetests (skipped) … status on this commit. Use /azp run maui-pr-devicetests for the full suite.

🤖 Why these tests — AI rationale (GPT-6.2 Sol + MAI Code 2)

UI tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android — —
iOS CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7, CarouselView CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7, CarouselView
MacCatalyst CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7, CarouselView CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7, CarouselView
Windows — —

GPT-6.2 Sol — Run CollectionView and CarouselView UI tests on iOS and Mac Catalyst for the Items2 scroll-anchor change.

  • CollectionViewScrollAnchor changes how UIKit layout animations affect edge following.
  • ItemsViewController2 changes shared Items2 layout hooks; include CarouselView.
  • No Android, Windows, or unrelated UI coverage.

MAI Code 2 — iOS and Mac Catalyst CollectionView2 scroll-anchor fix; runs CollectionView and CarouselView coverage on both platforms.

  • CollectionViewScrollAnchor and ItemsViewController2 change the iOS Items2 layout/animation handling, which is shared by UIKit and Mac Catalyst.
  • Items2 affects both CollectionView and CarouselView behavior, so both UI categories are needed on iOS and Mac Catalyst.
  • The changed device test directly validates CollectionView ScrollAnchorMode end-following behavior on iOS/Mac Catalyst; Android and Windows are unaffected.
  • Narrow selection avoids unrelated controls and a platform-wide/full run because the change is confined to the UIKit Items2 scroll anchor.

Device tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android — —
iOS Controls.CollectionView, Controls.CarouselView Controls.CollectionView, Controls.CarouselView
MacCatalyst Controls.CollectionView, Controls.CarouselView Controls.CollectionView, Controls.CarouselView
Windows — —

GPT-6.2 Sol — Run CollectionView and CarouselView device tests on iOS and Mac Catalyst, including the new scroll-anchor regression.

  • CollectionViewTests.ScrollAnchor adds an iOS/Mac Catalyst regression for short rows and end anchoring.
  • Cover CarouselView for the shared Items2 controller hooks.
  • No Core handler or other platform changes.

MAI Code 2 — Run CollectionView and coupled CarouselView device tests on iOS and Mac Catalyst for the Items2 anchor-animation fix.

  • The fix is in the iOS Items2 handler path and also compiles for Mac Catalyst.
  • The changed CollectionView device test covers the newly handled UIKit layout-started scroll animation.
  • Items2 backs both CollectionView and CarouselView, so both Controls device units are coupled to the changed anchor logic.
  • No Android, Windows, Core, Graphics, or Essentials device tests are needed because none use this iOS-specific code path.

Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification.

@github-actions github-actions Bot 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.

Expert Review — 1 finding · ⚠️ 1 breaking change

Reviewed commit 06dd7c4.

Warning

Existing apps would look or behave differently without opting in. See the Behavioral Change Disclosure findings at:

See inline comments for details.

if (!_animatingBeforeLayout && isVertical && _tracker.IsAnchored && _edgeAnimation is null && !_animatingRequest
&& !collectionView.Dragging && !collectionView.Decelerating && IsScrollAnimating(collectionView))
{
ApplyOffset(collectionView, collectionView.ContentOffset.Y);

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.

[major] Behavioral Change Disclosure - This also stops deliberate native animations in existing controller customizations. On iOS/MacCatalyst 17.4+, a custom controller supplied through CollectionViewHandler2.CreateController can call base.ViewWillLayoutSubviews() and then CollectionView.SetContentOffset(target, true) while a vertical list follows its end, with fully measured, unchanged content and an in-bounds target 100 points above the end. Before, the native animation could reach its target and release anchoring; now this branch cancels it before arrival. LayoutStarting recorded no animation, native scrolling sets neither request flag, and Scrolled defers tracking while layout depth is positive, so all cancellation conditions match without any content shrinkage. There is no opt-in/opt-out preserving both anchoring and this native customization; AnchorMode=None disables anchoring altogether. Distinguish an automatic shrink/out-of-bounds adjustment from a deliberate native animation before cancelling it. Add a regression test starting the deliberate animation between layout start and finish: the existing native-animation test starts before layout, while the new short-row test exercises only automatic correction.

@kubaflo
kubaflo merged commit 548a665 into main Nov 30, 2026
15 of 18 checks passed
@kubaflo
kubaflo deleted the simonrozsival-catalyst-scroll-anchor-shrink-flake branch November 30, 2026 13:26

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 06dd7c47 Deployed Nov 30, 2026 by simonrozsival via conclusion #3506
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants