Repository navigation
[iOS] ScrollView: Keep the content offset when the scroll view is resized by its parent layout - #38599
Conversation
<!-- 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! ## Summary - preserve `PatchVersion` at `110` - change `PreReleaseVersionLabel` from `ci.main` to `servicing` - remove the `inflight/current` `ci.inflight` label override - enable `StabilizePackageVersion` by default while preserving explicit overrides ## Validation Evaluated the properties with MSBuild for the default environment, `BUILD_SOURCEBRANCH=refs/heads/inflight/current`, and an explicit `StabilizePackageVersion=false` override. Both branch environments resolve to patch 110 and the `servicing` label; stabilization defaults to `true`, while the explicit `false` override remains honored. ## Scope This PR only prepares stable SR11 package versioning on `release/10.0.1xx-sr11`. It does not change `main`, resolve outstanding regression or backport decisions, update BAR state, or trigger release pipelines. Final release-head validation is still required after any later backports. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ger accepts OS-locale decimal separator (dotnet#38483) Backport of dotnet#38277 to release/10.0.1xx-sr11 /cc @kubaflo @HarishwaranVijayakumar Co-authored-by: HarishwaranVijayakumar <harishwaran.vijayakumar@syncfusion.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 169298fa-95aa-47a4-ad1c-512dc3f97871
…n removing items from grouped CollectionView (dotnet#38482) Backport of dotnet#38341 to release/10.0.1xx-sr11 /cc @kubaflo @Vignesh-SF3580 Co-authored-by: Vignesh-SF3580 <102575140+Vignesh-SF3580@users.noreply.github.com>
…essException when picking 2+ items (dotnet#38481) Backport of dotnet#37879 to release/10.0.1xx-sr11 /cc @kubaflo @pierre-galaup Co-authored-by: Pierre Galaup <pierregalaup@outlook.fr>
… remaining non-interactive after IsEnabled toggle (dotnet#38480) Backport of dotnet#37849 to release/10.0.1xx-sr11 /cc @kubaflo @SyedAbdulAzeemSF4852 Co-authored-by: SyedAbdulAzeemSF4852 <syedabdulazeem.a@syncfusion.com>
…coverage (dotnet#38489) > [!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! Backport of dotnet#37708 to `release/10.0.1xx-sr11` using a focused manual fallback after the automated backport failed: https://github.com/dotnet/maui/actions/runs/34705427768 Source squash commit: `90c55197d1925f99480482d51be7f53aae0d194c` (issue dotnet#37691). SR11 already inherits the runtime fix through `7c523245e64fca92f376a76298ed6cfd263cad3e`, including `ClearKeyboardState()` and the stronger `InvalidateSafeAreaWithDescendants()` behavior. This fallback intentionally preserves that runtime and adds only the two missing regression test files from the source squash commit. ## Validation - Both added files are byte-identical to their blobs in source commit `90c55197d1925f99480482d51be7f53aae0d194c`. - `src/Core/src/Platform/iOS/MauiView.cs` is unchanged. - `eng/Versions.props` remains at `PatchVersion` 110. - The equivalent targeted test previously passed on iPhone 17 / iOS 26.5 with all three cycles restoring the bottom marker to 874. - A fresh SR11-targeted run was attempted on iPhone 17 / iOS 26.5, but executed 0 tests because this worktree lacked bootstrapped MAUI build tasks. The documented bootstrap was attempted and bounded; it did not complete in time, so no new SR11-local pass result is claimed. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…rashWhenPageUnloaded UITests failure (dotnet#38565) Backport of dotnet#38564 to release/10.0.1xx-sr11 /cc @kubaflo @TamilarasanSF4853 Co-authored-by: TamilarasanSF4853 <tamilarasan.velu@syncfusion.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…nViewRemovalsUseCurrentAdapterPositions (dotnet#38588) <!-- 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 The GroupedCollectionViewRemovalsUseCurrentAdapterPositions test is failing on iOS when running with CollectionView1 (CV1). The test was checked locally, and the crash can be reproduced with CV1. The same test scenario works properly with CollectionView2 (CV2). The PR changes are related to Android, while this test failure occurs only with iOS CV1. This test was added in dotnet#38482 ### Root Cause The test scenario causes an existing crash with CollectionView1 (CV1) on iOS. During the investigation, it was also found that the GroupFooterTemplate used in the sample contributes to the CV1 crash. The same scenario works correctly with CV2. The same behavior was reproduced with MAUI 10.0.0 without the PR changes, confirming that the failure is not related to this PR. ### Description of Change Updated the test to run only with CollectionView2 (CV2). This avoids the existing CV1-specific failure on iOS while continuing to validate the intended grouped CollectionView item removal scenario.
…ized by its parent layout A ScrollView whose frame is resized by its parent layout in the same pass in which its content becomes taller than the viewport ended up scrolled by half the resize delta, so a bound page (Grid Auto,*,Auto with the ScrollView in the star row, content and an Auto-row footer arriving together after the page is on screen) appeared with its first item partially hidden — offset 18 for a 36pt footer. The generic arrange sets Center and then Bounds so non-identity transforms keep working. On a UIScrollView, Bounds.Origin is the content offset and UIKit re-derives it inside setBounds: when the size changes, keeping the content under the view's center stable — i.e. it scrolls by half the delta. A KVO observer on contentOffset captured the move exactly there, under GridLayoutManager.ArrangeChildren. Pre-existing (reproduced on the 10.0.100 and 10.0.101 sources), not a regression of the recent ScrollView changes. Arranging must never scroll. ScrollViewHandler.PlatformArrange (iOS) — the call through which a parent layout resizes the scroll view — now remembers the content offset before the base arrange and puts it back if UIKit moved it, clamped to the range the new size currently allows. The clamp is the inset-aware range ScrollToAsync already uses, factored into ClampToScrollableRange and shared with GetTargetContentOffset. Kept in the scroll view's handler rather than the generic arrange helper (scroll-view-specific) or a Bounds override on MauiScrollView (UIKit implements contentOffset through setBounds:, so that would sit on every scroll frame). ScrollViewInitialOffsetInGridRow (iOS/MacCatalyst) covers static vs. async content × with vs. without a header row (the latter under the status bar, non-zero top inset), instrumenting the native scroll view and capturing the managed stack of the first offset move so a failure names its cause. The async-with-header case fails without the fix (offset 18) and passes with it; all four pass with it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38599Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38599" |
|
Hey there @@albyrock87! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
Hey there @albyrock87! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
| static Microsoft.Maui.Handlers.EntryHandler.MapBackground(Microsoft.Maui.Handlers.IEntryHandler! handler, Microsoft.Maui.IEntry! entry) -> void | ||
| static Microsoft.Maui.Handlers.DatePickerHandler.MapFlowDirection(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void | ||
| override Microsoft.Maui.Handlers.EditorHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void | ||
| override Microsoft.Maui.Handlers.ScrollViewHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
There was a problem hiding this comment.
Added in 73b8059 — the same single line appended to net-maccatalyst/PublicAPI.Unshipped.txt. Core.csproj now builds clean for net10.0-maccatalyst26.0 Release with the PublicAPI analyzer.
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
Restore eng/Versions.props to main so PR dotnet#38599 contains only the ScrollView fix and its tests/API declarations. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
/backport to release/10.0.1xx-sr11 |
|
Started backporting to |
…n the scroll view is resized by its parent layout (#38602) Backport of #38599 to release/10.0.1xx-sr11 /cc @kubaflo @albyrock87 Co-authored-by: Alberto Aldegheri <albyrock87@gmail.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…38621) This PR addresses UI test failures in the main branch caused in this PR #38599. And it updates the `AssertRestsAtTop` test method to improve platform-specific handling for iOS devices. The main change is that the calculation and assertion logic for verifying the top position of the first item in the `ScrollView` is now only applied when running on iOS, ensuring more accurate and relevant test behavior for that platform. **Platform-specific test logic:** * In `ScrollViewInitialOffsetInGridRow.cs`, the calculation and assertion for the first item's top position relative to the `ScrollView` are now executed only for iOS devices, with updated comments clarifying the logic and rationale for this conditional handling. **Cause:** On Mac Catalyst, Appium element rectangles use desktop screen coordinates, which cannot be reliably combined with UIKit’s AdjustedContentInset. This caused false failures in the visual geometry assertion. **Fix:** Restrict the geometry assertion to iOS. Mac Catalyst continues to validate the behavior using the native ContentOffset and managed ScrollY checks reported by the HostApp. Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Description of Change
On iOS, a
ScrollViewwhose frame is resized by its parent layout in the same pass in which its content becomes taller than the viewport ends up scrolled by half the resize delta, so the page appears with the first item partially hidden. The common shape is a bound page: aGrid(Auto,*,Auto) with theScrollViewin the star row, whose content and an Auto-row footer arrive from the ViewModel after the page is already on screen — the footer grows, the star row shrinks, the content grows, and the ScrollView lands at e.g. offset 18 instead of 0 (contentPadding8 + itemMargin8 + stroke 2 scrolled away).Cause.
ViewHandlerExtensions.PlatformArrangeHandlerarranges views by settingCenterand thenBounds(rather thanFrame, so non-identity transforms keep working). On aUIScrollView,Bounds.Originis the content offset, and UIKit re-derives it insidesetBounds:when the size changes — it keeps the content under the view's center stable, i.e. it scrolls by half the delta. A KVO observer oncontentOffsetcaptured the move exactly there:The arrange defect itself is old: the fixture fails identically on the
10.0.90(SR9),10.0.100and10.0.101sources, so it is not a regression of the recent ScrollView changes. What changed in SR10 is reachability: #32267 madeMauiScrollView.InvalidateMeasure(isPropagating: true)returntrue, so a content change inside a ScrollView now propagates measure invalidation to its ancestors (needed so a content-sized ScrollView shrinks when children are removed). Before SR10 the ScrollView was a propagation barrier and a bound page's content arrival never re-laid-out the page; since SR10 it does — and a page host that applies insets or chrome on every layout pass (a custom scaffold, say) can then resize the ScrollView in the very pass its content grows. That is why an app can be clean on SR9 and hit this on SR10/SR11 with no code change of its own; the fixture forces the resize explicitly (a bound footer growing with the content) so it reproduces on every version.Fix. Arranging a scroll view must never scroll it.
ScrollViewHandler.PlatformArrange(iOS) — the call through which a parent layout resizes the scroll view — now remembers the content offset before the base arrange and puts it back if UIKit moved it, clamped to the range the new size currently allows. The clamp is the same inset-aware rangeScrollToAsyncalready uses (ClampToScrollableRange, shared withGetTargetContentOffset: rest is-AdjustedContentInset, the maximum extends past the arranged extent by the trailing inset). Kept in the ScrollView handler rather than the generic arrange helper or aBoundsoverride onMauiScrollView: it is scroll-view-specific, only the arrange path is affected, and UIKit implementscontentOffsetthroughsetBounds:so an override there would sit on every scroll frame. A view the user had scrolled keeps its position across a resize, exactly as UIKit's ownsetFrame:semantics would. Side effect worth knowing: in the affected passScrolledis raised twice (UIKit's spurious move, then the restore) — the final state is correct, whereas before the fix the spurious one was raised and kept.No public API change beyond the
PlatformArrangeoverride itself.Workaround for affected versions
The override is public, so an app (or a library hosting pages) can apply the same correction without waiting for the fix, by registering a handler subclass on iOS/MacCatalyst:
Notes: it clamps against
ContentSizerather than the internal arranged extent, which is equivalent for this purpose; it replaces the ScrollView handler globally, so combine it with any custom ScrollView handler the app already registers; and once on a fixed version it becomes a harmless no-op that can be removed. Merely deferring the content population to a later tick than other layout changes also avoids the coincidence in plain layouts, but is not reliable under hosts that re-apply insets on every layout pass.Note on #32267 — the enabler, and why it deserves a different approach
#32267 is what made this reachable from SR10 on, and we think its approach should be revisited on
main, independently of this fix.What it set out to do is legitimate. A ScrollView sized by its content — a
StackLayoutchild, anAutorow,VerticalOptions=Start— must make its parent re-measure when its content shrinks, or it keeps blank space at the bottom (#32221, #20586, #34536).How it did it is the problem.
MauiScrollViewwas deliberately a measure-invalidation barrier (InvalidateMeasure(isPropagating: true)returnedfalse; the surrounding code still says "Invalidation stops atUIScrollViews for performance reasons"), and it already had the targeted escape hatch for the content-sized case:LayoutSubviewscallsInvalidateAncestorsMeasures()whenContentSizechanges. #32267's diff is a single line that flips the barrier off unconditionally (return true), so every invalidation raised anywhere inside a ScrollView now walks up and re-measures the entire page, regardless of whether the ScrollView's size can even change.Performance cost. A ScrollView in a star row, in
Fill, or with an explicit size is fully constrained by its parent: its ancestors can learn nothing from its content changing, yet since SR10 each such change — a bound list populating, aLabeltext update, every keystroke in anEntryorEditorinside the scroll view — invalidates and re-measures the page above it. The scroll view is the single most common container for content-heavy pages, so this is paid constantly, on the main thread, for no layout result. The old barrier existed precisely to avoid that.Correctness cost. Turning arbitrary content changes into page re-layouts is what creates the coincidence this PR fixes: a page host that applies insets or chrome on each layout pass now resizes the ScrollView in the very pass its content grows. The arrange defect predates SR10, but SR10 is what makes ordinary bound pages hit it.
What the fix should have been. The reported root cause was that, on the first pass after removing children,
CrossPlatformMeasurereturned the ScrollView's current size, soContentSizedid not change and the existingInvalidateAncestorsMeasures()never fired. The proportionate fix addresses that: propagate only when the ScrollView's own measured size can actually change — i.e. when it is not size-constrained by its parent — and/or when its measured size differs from what the parent last measured. That keeps the content-sized case correct while leaving the barrier in place for every constrained ScrollView, which is the overwhelmingly common one. We would suggest reverting the unconditionalreturn truein favour of such a condition as a follow-up onmain; it is out of scope for a servicing fix, and this PR is deliberately independent of it — it fixes the arrange defect regardless of what triggers the resize.Separately, the XML doc on
IPlatformMeasureInvalidationController.InvalidateMeasureinMauiScrollViewsays the return value means "stop propagating", while the walk inViewExtensions.InvalidateAncestorsMeasurestreatstrueas "keep propagating". The doc is inverted and worth a one-line correction — it makes changes like #32267 easy to misjudge.Issues Fixed
Reported against 10.0.101 (page hosted in a custom scaffold with bound content). Reproduces with plain
NavigationPage+Grid.Tests
ScrollViewInitialOffsetInGridRow(iOS + MacCatalyst): a pushed, edge-to-edge page with aGrid Auto,*,Auto, theScrollViewin the star row, contentVerticalStackLayout Padding=0,8whose first child is aBorder Margin=16,8, in five cases — static vs. async content (content and a footer banner arriving together after appearing) × with vs. without a header row (the latter puts the ScrollView under the status bar, so the top inset is non-zero), plus a guard where the content is tall and laid out from the start and only the footer grows later: an ordinary resize of a laid-out scroll view does not scroll it (verified without the fix), and the restore must keep it that way. The page instruments the nativeUIScrollView(offset, adjusted/content/safe insets, content size, bounds, content frame,ScrollY) and, via KVO, the managed stack of the first offset move, so a failure names its cause. Oracles: native offset== -AdjustedContentInset.TopandScrollY == 0once the content is laid out; and, Appium-side, the first item's top exactly 16 below the ScrollView's visible top.Results on this commit (iOS simulator, iPhone 11 Pro):
Issue36801+Issue36801DeferredElement+ShellFlyoutHeaderScrollViewContentsuites 12/12AsyncContentWithHeaderfails atoffset=18(36pt footer growth, halved); the same case fails identically against the10.0.90,10.0.100and10.0.101sources forsrc/Core/src+src/Controls/src/CoreScrollEventProxy+NotifyInsetsChangeddisabled: still fails with the sameset_Boundsstack,ScrollYleft at 0 while the native offset is 18 — those paths only report the offsetStaticContentResizedLaterpasses with and without the fix (the guard)🤖 Generated with Claude Code