Repository navigation
[Android] Prevent vertical scroll in horizontal ScrollView #37880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ceb5b93
2e94dcc
e4a8a26
3b9b0d6
7f6d2f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| var hScrollViewWidth = Math.Max(0, this.MeasuredWidth - PaddingLeft - PaddingRight); | ||
|
|
||
| _hScrollView.Measure(MeasureSpec.MakeMeasureSpec(hScrollViewWidth, MeasureSpecMode.Exactly), | ||
| MeasureSpec.MakeMeasureSpec(hScrollViewHeight, MeasureSpecMode.Exactly)); | ||
|
|
@@ -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); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
[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 |
||
|
|
||
| //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); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
[major] Performance-Critical Path Optimization — |
||
| } | ||
|
|
||
| // Handle RTL initial positioning | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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.
NestedScrollViewcomputes its range aschildHeight - (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 fromCanScrollVertically(1). The short-control case therefore still exhibits the reported vertical scrolling.