Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 7 additions & 5 deletions src/Core/src/Platform/Android/MauiScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,10 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
// to be the same size as the NestedScrollView this way it can't be scrolled vertically
if (_hScrollView?.Parent == this && _content is not null && !_isBidirectional)
{
var hScrollViewHeight = this.MeasuredHeight;
var hScrollViewWidth = this.MeasuredWidth;
// Subtract padding (e.g. from SafeArea insets) so the child fits the content area exactly;
// otherwise NestedScrollView sees the overflow as vertical scroll range.
var hScrollViewHeight = Math.Max(0, this.MeasuredHeight - PaddingTop - PaddingBottom);

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)

[major] Layout Measure-Arrange Correctness — Clamping the child height to zero does not eliminate the vertical range when the padding is at least the view height. NestedScrollView computes its range as childHeight - (height - PaddingTop - PaddingBottom), so a 40 px horizontal ScrollView with a 60 px top safe-area inset gets a 0 px child but still has a 20 px range and returns true from CanScrollVertically(1). The short-control case therefore still exhibits the reported vertical scrolling.

var hScrollViewWidth = Math.Max(0, this.MeasuredWidth - PaddingLeft - PaddingRight);

_hScrollView.Measure(MeasureSpec.MakeMeasureSpec(hScrollViewWidth, MeasureSpecMode.Exactly),
MeasureSpec.MakeMeasureSpec(hScrollViewHeight, MeasureSpecMode.Exactly));
Expand All @@ -397,13 +399,13 @@ protected override void OnLayout(bool changed, int left, int top, int right, int
if (_hScrollView?.Parent == this && _content is not null)
{
var scrollViewContentHeight = _content.Height;
var hScrollViewHeight = bottom - top;
var hScrollViewWidth = right - left;
var hScrollViewHeight = Math.Max(0, (bottom - top) - PaddingTop - PaddingBottom);
var hScrollViewWidth = Math.Max(0, (right - left) - PaddingLeft - PaddingRight);

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)

[major] Logic and Correctness Verification — Narrowing an already-laid-out RTL viewport after an inset change leaves it short of the logical start. For example, a 2,000 px child initially reaches the RTL edge at ScrollX=1000 in a 1,000 px viewport; adding 100 px of side padding makes the new maximum 1,100, but _checkedForRtlScroll remains true and HorizontalScrollView retains 1,000, hiding the rightmost 100 px. This occurs when SafeAreaEdges or window insets change after layout, while the new test sets padding only before the first layout.


//if we are scrolling both ways we need to lay out our MauiHorizontalScrollView with more than the available height
//so its parent the NestedScrollView can scroll vertically
hScrollViewHeight = _isBidirectional ? Math.Max(hScrollViewHeight, scrollViewContentHeight) : hScrollViewHeight;
_hScrollView.Layout(0, 0, hScrollViewWidth, hScrollViewHeight);
_hScrollView.Layout(PaddingLeft, PaddingTop, PaddingLeft + hScrollViewWidth, PaddingTop + hScrollViewHeight);

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)

[major] Performance-Critical Path Optimization — PaddingLeft and PaddingTop are each read twice here after already being read for the size calculations above. These Android View getters cross JNI, adding four redundant managed/native calls on every horizontal or bidirectional OnLayout; cache the padding values once per pass.

}

// Handle RTL initial positioning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,35 @@ await InvokeOnMainThreadAsync(() =>
Assert.Equal(1000, measuredHeight);
});
}

[Fact]
[Category(TestCategory.ScrollView)]
public async Task MauiScrollViewHasNoVerticalScrollRangeWithPaddingInHorizontalOrientation()
{
await InvokeOnMainThreadAsync(() =>
{
var sv = new MauiScrollView(MauiContext.Context);
sv.SetContent(new Button(MauiContext.Context));
sv.SetOrientation(ScrollOrientation.Horizontal);
sv.SetPadding(10, 20, 30, 40);

var hsv = sv.FindViewWithTag("Microsoft.Maui.Android.HorizontalScrollView") as MauiHorizontalScrollView;
Assert.NotNull(hsv);

sv.Measure(
MeasureSpec.MakeMeasureSpec(1000, global::Android.Views.MeasureSpecMode.Exactly),
MeasureSpec.MakeMeasureSpec(1000, global::Android.Views.MeasureSpecMode.Exactly));

sv.Layout(0, 0, 1000, 1000);

Assert.Equal(960, hsv.MeasuredWidth);
Assert.Equal(940, hsv.MeasuredHeight);
Assert.Equal(10, hsv.Left);
Assert.Equal(20, hsv.Top);
Assert.Equal(970, hsv.Right);
Assert.Equal(960, hsv.Bottom);
Assert.False(sv.CanScrollVertically(1));
});
}
}
}
Loading