Skip to content

iOS: ScrollView with SafeAreaEdges="Container" reserves the safe area twice — phantom scroll range of exactly the inset size #36800

Closed

Description

@albyrock87

Description

On iOS, a ScrollView with SafeAreaEdges="Container" becomes scrollable even when its content is much smaller than the viewport. The phantom scroll range is exactly the sum of the safe-area insets (e.g. 82 pt on an iPhone 11: 48 status bar + 34 home indicator). With content taller than the viewport, the same defect appears as dead over-scroll space at the end of the content.

Root cause: MAUI reserves the safe area twice for this configuration:

  1. MauiScrollView.UpdateContentInsetAdjustmentBehavior() maps SafeAreaRegions.Container to UIScrollViewContentInsetAdjustmentBehavior.Always, so UIKit reserves the safe area via adjustedContentInset.
  2. MauiScrollView.CrossPlatformArrange(...) also adds the safe-area thickness to the native contentSize.

The scrollable range of a UIScrollView is contentSize + adjustedContentInset - bounds, so the safe area is counted twice and the view over-scrolls by exactly _safeArea.VerticalThickness (and HorizontalThickness horizontally).

Versions

Reproduced on Microsoft.Maui.Controls 10.0.80 and 10.0.90, net10.0-ios, iPhone 11 simulator (iOS 26.2). Present in release/10.0.1xx sources.

Steps to Reproduce

  1. dotnet new maui, target net10.0-ios.
  2. Make the page edge-to-edge and give the ScrollView the safe area to consume:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Repro.MainPage"
             SafeAreaEdges="None">
    <ScrollView x:Name="Scroll" SafeAreaEdges="Container">
        <VerticalStackLayout Padding="16" Spacing="12">
            <Label Text="Small content" FontSize="22" />
            <Button Text="Dump native state" Clicked="OnDump" />
            <Label x:Name="Diag" FontSize="10" />
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>
  1. Add the diagnostic handler:
void OnDump(object? sender, EventArgs e)
{
#if IOS
    if (Scroll.Handler?.PlatformView is UIKit.UIScrollView native)
    {
        Diag.Text = $"bounds={native.Bounds.Size} contentSize={native.ContentSize} " +
                    $"adjusted={native.AdjustedContentInset} behavior={native.ContentInsetAdjustmentBehavior}";
    }
#endif
}
  1. Run on an iPhone simulator and drag the page vertically.

Expected Behavior

Content fits on screen → the ScrollView is not scrollable. Native state should satisfy contentSize + adjustedContentInset.Top + adjustedContentInset.Bottom <= bounds.Height.

Actual Behavior

The page scrolls by exactly the safe-area sum. Measured on iPhone 11 (896 pt tall, safe insets 48 top / 34 bottom):

bounds      = {414, 896}
contentSize = {414, 896}   // = 814 (arranged content, viewport minus insets) + 82 (insets, added again)
adjusted    = {48, 0, 34, 0}
behavior    = Always

Scroll range = 896 + 82 - 896 = 82 pt of phantom scrolling. The cross-platform ScrollView.ContentSize property reports the correct {414, 814} — only the native contentSize is inflated.

(When the scroll view sits inside a container contributing AdditionalSafeAreaInsets — e.g. custom chrome — the phantom range grows accordingly; the defect scales with whatever the safe area is.)

Root Cause (code)

src/Core/src/Platform/iOS/MauiScrollView.cs, CrossPlatformArrange(CGRect bounds):

// arrange: for the Always path the content is arranged at ORIGIN ZERO with inset-reduced size
if (SystemAdjustedContentInset == UIEdgeInsets.Zero || ContentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentBehavior.Never)
{
    contentSize = CrossPlatformLayout?.CrossPlatformArrange(bounds.ToRectangle()) ?? Size.Zero;   // bounds was inset via _safeArea.InsetRect
    ...
}
else
{
    contentSize = CrossPlatformLayout?.CrossPlatformArrange(new Rect(new Point(), bounds.Size.ToSize())) ?? Size.Zero;
    ...
}

...

if (ContentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentBehavior.Automatic)
{
    // (separate "keep scrollable" logic, not involved here)
}
else if (ContentInsetAdjustmentBehavior != UIScrollViewContentInsetAdjustmentBehavior.Automatic)
{
    width += _safeArea.HorizontalThickness;    // <-- BUG for the Always path
    height += _safeArea.VerticalThickness;     // <-- BUG for the Always path
}

The += thickness compensation is only correct when the content was arranged at the inset origin (the Never / zero-inset branch above — there the canvas itself must contain the padding). For Always with active system insets, the content is arranged at origin zero and UIKit already reserves the safe area through adjustedContentInset — adding the thickness to contentSize double-counts it.

Proposed Fix

Make the contentSize compensation mirror the arrange-origin decision — pad only when the content was arranged at the inset origin:

else if (SystemAdjustedContentInset == UIEdgeInsets.Zero || ContentInsetAdjustmentBehavior == UIScrollViewContentInsetAdjustmentBehavior.Never)
{
    // Content was arranged at the inset origin: the scrollable canvas must include the padding.
    width += _safeArea.HorizontalThickness;
    height += _safeArea.VerticalThickness;
}
// else: Always with active system insets — content is at origin zero and UIKit reserves the
// safe area via adjustedContentInset; padding contentSize would reserve it twice.

Verification checklist for the fix

  • Small content, SafeAreaEdges="Container": not scrollable; rest offset -adjustedContentInset.Top.
  • Tall content, SafeAreaEdges="Container": max content offset = contentSize.Height + adjustedContentInset.Bottom - bounds.Height; the last element rests fully above the home indicator; content scrolls edge-to-edge under the bars.
  • SafeAreaEdges="None" and default (Automatic) paths unchanged.
  • Rotation and keyboard scenarios unchanged (_safeArea recomputation already invalidates layout).

Activity

  1. added
    area-controls-general
    on Jul 26, 2026
  2. TamilarasanSF4853 commented on Jul 27, 2026

    @TamilarasanSF4853
    Contributor

    This issue has been validated in Visual Studio Code 1.130.0 with .NET MAUI versions 10.0.0, 10.0.80 and 10.0.90. It can be reproduced on the iOS platform.

    ScrollViewSafeAreaIssue.zip

    Screen.Recording.2026-07-27.at.1.01.57.PM.mov
  3. added
    s/verified
    s/triaged
    on Jul 27, 2026
  4. added this to the .NET 10 SR11 milestone on Jul 27, 2026
  5. added
    partner/syncfusion
    on Aug 7, 2026
  6. 13 remaining items

  7. kubaflo commented on Oct 10, 2026

    @kubaflo
    Contributor

    Thank you for the report and the investigation details. We are closing this as completed: the iOS ScrollView no longer adds manual content-size padding when UIKit already supplies adjusted insets, removing the reported double reservation and phantom scroll range.

    Supporting evidence: #37765 (merged into inflight/current).

    This records the merged source change; it does not imply that the fix is present in every released .NET MAUI package.

    If you can still reproduce the reported behavior in a build that includes the linked change, please comment here with the exact version and reproduction details so we can reopen and investigate. The existing reproduction and discussion remain available; a new issue is not required.

  8. locked and limited conversation to collaborators on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-generalpartner/syncfusionplatform/ioss/triageds/verified

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions