Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
a8e8d6d
Never park an element request a collapsed branch cannot retry; share …
albyrock87 Aug 11, 2026
d79d09c
Restore Automatic expectations for SafeAreaEdges.Default after the la…
albyrock87 Aug 13, 2026
9f439ed
Convert the last raw occurrence of the shared safe-area predicate
albyrock87 Aug 14, 2026
7306000
Check every visual ancestor's visibility, skipping non-visual links i…
albyrock87 Aug 14, 2026
7f625b3
Release the caller but keep an element request parked while its branc…
albyrock87 Aug 14, 2026
7e4f1bf
Capture the baked safe area at arrange time instead of deriving it live
albyrock87 Aug 15, 2026
a3323ee
Release a parked element request when its view is collapsed or repare…
albyrock87 Aug 15, 2026
567c5a1
Merge branch 'inflight/current' into fix-36801-followup-collapsed-ele…
kubaflo Aug 15, 2026
74e9c16
Give a parked element request one contract: it lives exactly as long …
albyrock87 Aug 15, 2026
f02311a
Merge remote-tracking branch 'upstream/inflight/current' into fix-368…
albyrock87 Aug 15, 2026
6ec1c5a
Restore the PublicAPI files to the merge target
albyrock87 Aug 15, 2026
c56e736
Scope the deferred completion to the lifecycle-drop path
albyrock87 Aug 16, 2026
fa03bc0
Complete a dropped request inline, bound to the request being dropped
albyrock87 Aug 16, 2026
386214e
Gate an element request on the geometry its target actually needs; ca…
albyrock87 Aug 18, 2026
efdf0d9
Let a request made from inside the replayed ScrollToRequested event w…
albyrock87 Aug 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 52 additions & 9 deletions src/Controls/src/Core/ScrollView/ScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,29 @@ void DispatchPendingScrollToRequest()
return;
}

if (pending.Mode == ScrollToMode.Element)
if (pending.Mode == ScrollToMode.Element && !IsElementTargetGeometryReady())
{
if (!IsElementTargetGeometryReady())
if (!WillArrange())
{
// The request has to wait; OnSizeAllocated and ContentSizeChanged retry it.
return;
// A collapsed branch is skipped by layout, so no callback is coming to
// resolve the target. Release the caller now, but keep the request
// parked: if the branch is later shown, the first arrange replays it
// against real geometry so the scroll still lands on the element
// (a newer request supersedes it as usual).
SendScrollFinished();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[moderate] Cross-Platform Behavioral Consistency — Releasing the caller while leaving the request parked means await ScrollToAsync(element, …) can report completion and then perform the scroll an arbitrary amount of time later, when the branch is next shown. Concrete scenario: a collapsed detail panel whose ScrollToAsync(item, Center) is awaited during OnAppearing; the user expands the panel minutes later and the ScrollView jumps to a target chosen for stale content. Only a subsequent ScrollToAsync clears the park (_pendingScrollToRequested = null, line 621) — the caller that was already released has no way to cancel it, and ScrollX/ScrollY have no public setter to override it. Worth confirming this deferred replay is the intended contract versus dropping the parked request at release time (which would make Task completion mean "this request is over" on every path).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adopted in fd0c039 — and this finding is the one that resolved the whole series, so thank you for it. You're right that releasing the task while leaving the request parked meant a completed await could scroll arbitrarily later with no way to cancel it; that is a ghost scroll, and it's the exact hazard I'd argued against on the detach thread in #37060. The park-and-complete design was internally contradictory and every prior round was one end of that contradiction being pulled.

Replaced with a single invariant, now stated in the code and the PR description: a parked element request lives exactly as long as its task. It leaves the park in exactly two ways and no other — the arrange arrives and it's replayed against real geometry (task completes with the scroll), or the view's lifecycle ends (handler goes away / removed from the tree) and it's dropped (task completes without a scroll). Nothing releases the task while a request is parked, so completion means "this request is over" on every path; nothing but a lifecycle end drops it, so a merely hidden view still scrolls to the element once shown. The visibility-proxy machinery (WillArrange, OnIsVisibleChanged, the collapse releases) is gone entirely — every proxy for "no arrange is coming" leaks, and each leak was a hang.

}

// Those callbacks run while the pass that produced the sizes is still arranging
// children, so resolve on the next tick, once positions are final. Posting on
// every retry is deliberate: SendPendingScrollToRequest is a no-op once the
// request has been sent or superseded, so a dropped callback cannot wedge the
// request the way an "already queued" flag would.
// The request has to wait; OnSizeAllocated and ContentSizeChanged retry it.
return;
}

if (pending.Mode == ScrollToMode.Element)
{
// The geometry callbacks run while the pass that produced the sizes is still
// arranging children, so resolve on the next tick, once positions are final.
// Posting on every retry is deliberate: SendPendingScrollToRequest is a no-op
// once the request has been sent or superseded, so a dropped callback cannot
// wedge the request the way an "already queued" flag would.
Dispatcher.Dispatch(SendPendingScrollToRequest);
return;
}
Expand All @@ -101,6 +111,30 @@ void DispatchPendingScrollToRequest()
bool IsElementTargetGeometryReady() =>
Width >= 0 && Height >= 0 && Content is not ({ Width: < 0 } or { Height: < 0 });

// A parked element request is retried only from OnSizeAllocated/ContentSizeChanged,
// which fire when this view gets arranged — and a view inside a collapsed
// (IsVisible=false) branch is skipped by layout entirely, so a request parked there
// has no callback coming. In that state the awaiting caller is released immediately
// while the request stays parked: showing the branch arranges it and replays the
// scroll against real geometry (see DispatchPendingScrollToRequest).
// The walk checks IsVisible on every VisualElement ancestor, skipping over non-visual
// links in the chain (e.g. Shell's ShellContent/ShellSection) rather than stopping at
// them. Non-visual containers' own visibility semantics (a hidden tab, say) are
// deliberately not consulted: parking keeps the scroll correct if that container is
// ever shown, and a handler detach still completes the task.
bool WillArrange()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[moderate] Logic and Correctness — WillArrange() is only consulted at the moment a request is parked (OnScrollToRequested) and inside DispatchPendingScrollToRequest, which runs solely from OnHandlerChangedCore, OnSizeAllocated, and ContentSizeChanged. Nothing re-evaluates it when IsVisible changes, so the reverse ordering still hangs: ScrollToAsync(element, ...) from OnAppearing (handler attached, Width/Height still -1) parks the request with WillArrange() == true, and if the app then collapses the ScrollView or an ancestor before the first arrange (e.g. hiding content behind a loading overlay), no arrange callback ever fires, DispatchPendingScrollToRequest is never re-entered, and the awaited task never completes — the exact hang this PR fixes for the collapsed-at-request-time ordering. A retry from the IsVisible property-changed path (or completing the parked request when the branch becomes collapsed) would close the gap; the added unit tests only cover collapsed-before-request.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adopted in a3323ee, taking your "complete the parked request when the branch becomes collapsed" shape — and reversing my earlier rebuttal, honestly: park-and-complete changed the cost. The objection was that closing this ordering meant subscription machinery to replay the request on visibility transitions; now the request stays parked regardless and all a collapse has to do is release the caller, which is a one-line re-check. Both transitions with a real hook are covered: the ScrollView's own collapse (OnIsVisibleChanged) and reparenting into a collapsed branch (OnParentSet, the case your verdict also named). Two new unit tests cover exactly the parked-while-visible → collapsed-before-arrange ordering, including the later re-show replay landing on the element.

One boundary stated in the code rather than papered over: an ancestor collapsing after the park sends no signal down the tree — layout managers simply skip the collapsed child and nothing reaches descendants (I checked; MAUI has no downward visibility propagation) — so that request is released on re-show or handler detach. Closing it would need per-ancestor PropertyChanged subscriptions with re-walks on every reparent, whose lifecycle failure modes cost more than the ordering they'd cover.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[moderate] Logic and Correctness — WillArrange() uses "no collapsed VisualElement ancestor" as a proxy for "an arrange callback is coming", but the two are not equivalent, so the hang this PR fixes survives in adjacent states that the PR's own hooks nearly reach:

  1. Reparent to null. OnParentSet (line 156) fires when the ScrollView is removed from the tree, but WillArrange() then walks this → RealParent == null with IsVisible == true and returns true, so ReleaseParkedRequestIfCollapsed does nothing. A ScrollView removed from its parent does not automatically null its Handler, so OnHandlerChangedCore's release (line 55) does not fire either and the parked request's task stays pending forever — the original bug, one hook away from being covered.
  2. Unselected Shell tab. The comment at lines 120–123 states this is deliberate, but the consequence is the reported failure mode: for a page in a non-current ShellSection whose view controller's view is never loaded, no arrange occurs while Shell.IsVisible is true, so WillArrange() returns true and await ScrollToAsync(element, …) never completes.

No test covers either case — the five new unit tests all express "no arrange coming" as IsVisible = false on a VisualElement, which is precisely the subset the guard can detect, so a green suite cannot discriminate the guard's premise from the actual condition. Either widen the release condition (e.g. also release when RealParent is null while a handler is attached) or state in the PR that the remaining hang cases are out of scope.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both cases resolved in fd0c039, by removing the proxy rather than widening it. (1) Reparent-to-null is real — I verified LayoutHandler.Remove detaches only the platform view and leaves the child's handler connected, so a removed ScrollView held a parked request nobody would ever retry. Removal from the tree is now treated as what it is: a lifecycle end (OnParentSet with a null parent drops the request and completes the task), the same category as handler detach — not a visibility proxy. Test: ElementRequestIsDroppedAndCompletedWhenTheViewLeavesTheTree, which also asserts the dropped request is not resurrected if the view is re-attached and arranged later. (2) The unselected Shell tab is covered by the contract instead of a special case: an attached, never-arranged view keeps its task pending until the arrange happens or the view is torn down — which for a tab means the scroll lands correctly on the element the moment the tab is shown, strictly better than releasing early with a lost target. WillArrange() and its IsVisible walk no longer exist, so there is no premise left for a green suite to fail to discriminate.

{
for (Element element = this; element is not null; element = element.RealParent)
{
if (element is VisualElement { IsVisible: false })
{
return false;
}
}

return true;
}

void SendPendingScrollToRequest()
{
if (Handler is null || _pendingScrollToRequested is not { } pending)
Expand Down Expand Up @@ -535,6 +569,15 @@ void OnScrollToRequested(ScrollToRequestedEventArgs e)
// subscribers were already notified above, so the replay must not re-raise.
_pendingScrollToRequested = e;
_replayPendingScrollToRequestedEvent = false;

if (!WillArrange())
{
// A collapsed branch gets no layout callbacks, so parking alone would
// hang the caller. Complete the task now and leave the request parked:
// showing the branch arranges it and replays the scroll against real
// geometry.
SendScrollFinished();
}
}
else
{
Expand Down
84 changes: 84 additions & 0 deletions src/Controls/tests/Core.UnitTests/ScrollViewUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,90 @@ public void ElementRequestWithHandlerAttachedWaitsForArrange()
Assert.True(task.IsCompleted);
}

[Fact]
public void ElementRequestOnCollapsedScrollViewReleasesCallerAndReplaysWhenShown()
{
var item = new View();
var layout = new StackLayout { Children = { item } };
var scrollView = new ScrollView { Content = layout, IsVisible = false };

var handler = new ViewportProviderHandlerStub();
scrollView.Handler = handler;

// A collapsed ScrollView is skipped by layout, so no geometry callback is coming:
// the caller must be released immediately instead of hanging forever...
var task = scrollView.ScrollToAsync(item, ScrollToPosition.Center, false);
Assert.True(task.IsCompleted);

// ...but the request must not resolve against the -1 never-arranged sentinels —
// it stays parked instead of clamping a garbage target to the origin
Assert.Empty(handler.ScrollToRequests);

// Showing the branch arranges it; the first arrange replays the parked request
// against real geometry so the scroll still lands on the element
scrollView.IsVisible = true;
item.Layout(new Graphics.Rect(0, 450, 100, 50));
layout.Layout(new Graphics.Rect(0, 0, 100, 1000));
scrollView.Layout(new Graphics.Rect(0, 0, 100, 100));

// Center: 450 - 100/2 + 50/2
var request = Assert.Single(handler.ScrollToRequests);
Assert.Equal(425, request.VerticalOffset);
}

[Fact]
public void DeferredElementRequestOnCollapsedAncestorReleasesCallerOnAttach()
{
var item = new View();
var layout = new StackLayout { Children = { item } };
var scrollView = new ScrollView { Content = layout };
var parent = new StackLayout { IsVisible = false, Children = { scrollView } };

// Parked because the handler is missing, not because of visibility
var task = scrollView.ScrollToAsync(item, ScrollToPosition.Start, false);

var handler = new ViewportProviderHandlerStub();
scrollView.Handler = handler;

// On attach the collapsed ancestor means no arrange is coming: release the
// caller, but keep the request parked rather than resolving it against the
// never-arranged sentinels
Assert.True(task.IsCompleted);
Assert.Empty(handler.ScrollToRequests);

// Showing the ancestor arranges the branch and replays the request for real
parent.IsVisible = true;
item.Layout(new Graphics.Rect(0, 450, 100, 50));
layout.Layout(new Graphics.Rect(0, 0, 100, 1000));
scrollView.Layout(new Graphics.Rect(0, 0, 100, 100));

// Start aligns the element's top with the viewport top
var request = Assert.Single(handler.ScrollToRequests);
Assert.Equal(450, request.VerticalOffset);
}

[Fact]
public void CollapsedShellAncestorBeyondNonVisualLinksIsDetected()
{
var item = new View();
var layout = new StackLayout { Children = { item } };
var scrollView = new ScrollView { Content = layout };
var page = new ContentPage { Content = scrollView };
var shell = new Shell { IsVisible = false };
shell.Items.Add(new ShellContent { Content = page });

var handler = new ViewportProviderHandlerStub();
scrollView.Handler = handler;

// The ancestor chain crosses non-VisualElement links (ShellContent/ShellSection)
// before reaching the collapsed Shell: the visibility walk must skip over them
// rather than stop, so the caller is released immediately instead of parking
// behind an arrange that never comes
var task = scrollView.ScrollToAsync(item, ScrollToPosition.End, false);
Assert.True(task.IsCompleted);
Assert.Empty(handler.ScrollToRequests);
}

[Fact]
public void DeferredRequestReplaysEventForSubscribersAttachedWithTheHandler()
{
Expand Down
5 changes: 1 addition & 4 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue36801.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,7 @@ string CheckResolvedMode(UIKit.UIScrollView nativeScrollView, string kind)
var expected =
edges.Equals(new SafeAreaEdges(SafeAreaRegions.Container)) ? UIKit.UIScrollViewContentInsetAdjustmentBehavior.Always :
edges.Equals(SafeAreaEdges.None) || edges.Equals(SafeAreaEdges.All) ? UIKit.UIScrollViewContentInsetAdjustmentBehavior.Never :
// Default on a vertical scroll view resolves to Never since the landscape-notch
// fix (#35533): MAUI owns all edges there, and Automatic remains in use only for
// horizontal scroll views
UIKit.UIScrollViewContentInsetAdjustmentBehavior.Never;
UIKit.UIScrollViewContentInsetAdjustmentBehavior.Automatic;

return nativeScrollView.ContentInsetAdjustmentBehavior == expected
? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public void ScrollToElementEndLandsInsideVisibleViewport()
"Probe label should be fully visible after ScrollToAsync(element, End)");
}

// The reachable ContentInsetAdjustmentBehavior modes bake the safe area into the content
// The three ContentInsetAdjustmentBehavior modes bake the safe area into the content
// differently, so each is exercised. The page asserts the resolved native behavior, so a
// mode that silently drifted fails instead of quietly testing a different branch.
// Default on a vertical scroll view resolves to Never since the landscape-notch fix
// (#35533); Automatic remains in use only for horizontal scroll views.
// mode that silently drifted fails instead of quietly testing a different branch —
// exactly what happened when the landscape-notch fix (#35533, since reverted in #36580)
// briefly remapped Default to Never.
[Test]
[Category(UITestCategories.ScrollView)]
[TestCase("ModeDefaultButton", "Never")]
[TestCase("ModeDefaultButton", "Automatic")]
[TestCase("ModeNoneButton", "Never")]
// Also resolves to Never, but bakes the safe area into the arranged content, which None
// does not — so it is the case that actually exercises the measured extent's baked padding
Expand All @@ -97,13 +97,13 @@ public void ScrollToExtremesInEachInsetMode(string modeButton, string expectedMo
}

// Element targets resolve against the effective viewport, and each inset mode obscures it
// differently: Always through AdjustedContentInset, Default/SafeAreaEdges.All by baking
// differently: Automatic/Always through AdjustedContentInset, SafeAreaEdges.All by baking
// the safe area into the content where AdjustedContentInset never reports it. The page's
// oracle measures the probe's bottom edge against the unobscured viewport bottom in window
// coordinates, so the mode where MAUI itself obscures the viewport is proven too.
[Test]
[Category(UITestCategories.ScrollView)]
[TestCase("ModeDefaultButton", "Never")]
[TestCase("ModeDefaultButton", "Automatic")]
[TestCase("ModeNoneButton", "Never")]
// Also resolves to Never, but bakes the safe area into the content — the case where the
// viewport shrink comes from MAUI's own arrange instead of a UIKit inset
Expand Down
32 changes: 22 additions & 10 deletions src/Core/src/Platform/iOS/MauiScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ bool ValidateSafeArea()
// it can push ContentSize over the Bounds, causing AdjustedContentInset to become non-zero and SafeAreaInsets on the child to reset to zero.
// This can result in a loop of invalidations as the layout toggles between these states.
// To prevent this, we ignore safe area calculations on child views when they are inside a scroll view.
if (SystemAdjustedContentInset == UIEdgeInsets.Zero || ContentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentBehavior.Never)
if (!UIKitCompensatesForSafeArea)
_safeArea = GetInset().ToSafeAreaInsets();
else
_safeArea = SystemAdjustedContentInset.ToSafeAreaInsets();
Expand Down Expand Up @@ -481,6 +481,19 @@ internal CGSize ScrollableContentSize
/// </summary>
CGRect? _arrangedContentRect;

/// <summary>
/// Whether UIKit is compensating for the safe area through
/// <see cref="UIScrollView.AdjustedContentInset"/>. When it is not
/// (<see cref="UIScrollViewContentInsetAdjustmentBehavior.Never"/>, or a zero system
/// inset), <see cref="CrossPlatformArrange"/> bakes the safe area into the content's
/// coordinate space instead. Shared by the arrange branch, the <c>_safeArea</c> source
/// selection in <see cref="ValidateSafeArea"/>, and
/// <see cref="SafeAreaBakedIntoContent"/> so the sites can never desynchronize.
/// </summary>
bool UIKitCompensatesForSafeArea =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[minor] Complexity Reduction — the new property's summary states it is "shared by the arrange branch and SafeAreaBakedIntoContent so the two can never desynchronize", but a third occurrence of the identical predicate remains inline at line 395 (if (SystemAdjustedContentInset == UIEdgeInsets.Zero || ContentInsetAdjustmentBehavior == ...Never)), and that one selects the source of _safeArea — the very value SafeAreaBakedIntoContent returns. Leaving it duplicated means a future change to UIKitCompensatesForSafeArea silently diverges from the _safeArea computation it feeds, which is the desynchronization the refactor is meant to prevent. Converting line 395 to !UIKitCompensatesForSafeArea is behavior-preserving (the De Morgan negation matches exactly, as it does for the two sites already converted).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adopted in 9f439ed — the _safeArea source selection in ValidateSafeArea now uses !UIKitCompensatesForSafeArea too, and the property doc lists all three sites. You're right that leaving it inline kept alive exactly the desynchronization the refactor exists to prevent.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 AI-Generated Review (multi-model)

[minor] Safe Area and Window Insets — The extracted predicate is behavior-preserving (!(SystemAdjustedContentInset == Zero || Behavior == Never) is exactly the negation of both original inline conditions), but the doc claim that sharing it means the sites "can never desynchronize" and that SafeAreaBakedIntoContent "always describes what the last arrange actually did" is not what the change guarantees. Both CrossPlatformArrange and SafeAreaBakedIntoContent evaluate this property live against mutable UIKit state, and under Automatic UIKit turns AdjustedContentInset non-zero once ContentSize exceeds Bounds — i.e. as a result of the very arrange that just baked the inset. A later read of SafeAreaBakedIntoContent then returns Empty while the content coordinate space still carries the baked padding, which is the mismatch element-target resolution (#36801) depends on. Sharing a live expression removes textual divergence only; capturing the value the arrange actually used (as _arrangedContentRect already does for the rect) would deliver the stated invariant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adopted in 7e4f1bf — you're right that sharing a live expression only removes textual divergence, and the Automatic transition you describe (the arrange that bakes the padding pushes ContentSize past Bounds, UIKit flips the inset non-zero, a later live read says Empty while the content still carries the padding) is exactly the window that mattered. CrossPlatformArrange now records the baked padding from the branch it actually took, alongside _arrangedContentRect which already did the same for the rect, and SafeAreaBakedIntoContent returns that captured value — so the doc claim is now literally what the code does. UIKitCompensatesForSafeArea remains shared between the arrange branch and the _safeArea source selection, where the live evaluation is the correct semantics.

SystemAdjustedContentInset != UIEdgeInsets.Zero
&& ContentInsetAdjustmentBehavior != UIScrollViewContentInsetAdjustmentBehavior.Never;

/// <summary>
/// The safe area <see cref="CrossPlatformArrange"/> baked into the content's coordinate
/// space: when it applies the safe area while UIKit is not compensating through
Expand All @@ -489,16 +502,15 @@ internal CGSize ScrollableContentSize
/// padding still obscures the viewport without ever appearing in the adjusted inset.
/// </summary>
/// <remarks>
/// Mirrors the arrange-side branch exactly: bounds are inset only while
/// <c>_appliesSafeAreaAdjustments</c>, and the inset origin is kept only when UIKit
/// contributes nothing (<see cref="UIScrollViewContentInsetAdjustmentBehavior.Never"/>,
/// or a zero system inset). In the remaining case (<see cref="UIScrollViewContentInsetAdjustmentBehavior.Always"/>)
/// the content is re-based at the origin and UIKit's inset owns the compensation, so the
/// arranged rect <see cref="ScrollableContentSize"/> measures naturally excludes it (issue #36801).
/// Shares <see cref="UIKitCompensatesForSafeArea"/> with the arrange branch, so the
/// baked state always describes what the last arrange actually did: when UIKit is not
/// compensating, the content is arranged inside safe-area-inset bounds and the padding
/// lives in its coordinate space; when UIKit compensates, the content is re-based at
/// the origin and the adjusted inset owns the compensation, which the arranged rect
/// <see cref="ScrollableContentSize"/> measures naturally excludes (issue #36801).
/// </remarks>
internal SafeAreaPadding SafeAreaBakedIntoContent =>
_appliesSafeAreaAdjustments &&
(SystemAdjustedContentInset == UIEdgeInsets.Zero || ContentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentBehavior.Never)
_appliesSafeAreaAdjustments && !UIKitCompensatesForSafeArea
? _safeArea
: SafeAreaPadding.Empty;

Expand Down Expand Up @@ -538,7 +550,7 @@ Size CrossPlatformArrange(CGRect bounds)
CGPoint contentOrigin;
double width;
double height;
if (SystemAdjustedContentInset == UIEdgeInsets.Zero || ContentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentBehavior.Never)
if (!UIKitCompensatesForSafeArea)
{
contentSize = CrossPlatformLayout?.CrossPlatformArrange(bounds.ToRectangle()) ?? Size.Zero;
contentOrigin = bounds.Location;
Expand Down
Loading