From 7087bc7c283b2a28bc474ddf2195d5653063e1dd Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 1 Mar 2023 15:42:45 +0000 Subject: [PATCH 1/3] [Android] Fix bidirectional scrolling on Android --- src/Core/src/Platform/Android/MauiScrollView.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Platform/Android/MauiScrollView.cs b/src/Core/src/Platform/Android/MauiScrollView.cs index 034bf12073aa..488ea6f65578 100644 --- a/src/Core/src/Platform/Android/MauiScrollView.cs +++ b/src/Core/src/Platform/Android/MauiScrollView.cs @@ -187,9 +187,14 @@ protected override void OnLayout(bool changed, int left, int top, int right, int { base.OnLayout(changed, left, top, right, bottom); - if (_hScrollView != null && _hScrollView.Parent == this) + if (_hScrollView != null && _hScrollView.Parent == this && _content != null) { - _hScrollView.Layout(0, 0, right - left, bottom - top); + double scrollViewContentHeight = _content.Height; + var hScrollViewHeight = bottom - top; + //if we are scrolling both ways we need to layout our MauiHorizontalScrollView with more than the available height + //so it's parent the NestedScrollView can scroll vertically + var newBottom = _isBidirectional ? Math.Max(hScrollViewHeight, scrollViewContentHeight) : hScrollViewHeight; + _hScrollView.Layout(0, 0, right - left, (int)newBottom); } if (CrossPlatformArrange == null) From c29101a38a915399a85625c9e38ca0a66a9de21b Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Thu, 2 Mar 2023 11:38:12 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Samantha Houts --- src/Core/src/Platform/Android/MauiScrollView.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Platform/Android/MauiScrollView.cs b/src/Core/src/Platform/Android/MauiScrollView.cs index 488ea6f65578..ed81d7a0f8c6 100644 --- a/src/Core/src/Platform/Android/MauiScrollView.cs +++ b/src/Core/src/Platform/Android/MauiScrollView.cs @@ -191,8 +191,8 @@ protected override void OnLayout(bool changed, int left, int top, int right, int { double scrollViewContentHeight = _content.Height; var hScrollViewHeight = bottom - top; - //if we are scrolling both ways we need to layout our MauiHorizontalScrollView with more than the available height - //so it's parent the NestedScrollView can scroll vertically + //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 var newBottom = _isBidirectional ? Math.Max(hScrollViewHeight, scrollViewContentHeight) : hScrollViewHeight; _hScrollView.Layout(0, 0, right - left, (int)newBottom); } From 3068e2c1213466fe90f2af4e48c2019b676b6100 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Thu, 2 Mar 2023 11:10:11 +0000 Subject: [PATCH 3/3] Update src/Core/src/Platform/Android/MauiScrollView.cs Co-authored-by: Manuel de la Pena --- src/Core/src/Platform/Android/MauiScrollView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/src/Platform/Android/MauiScrollView.cs b/src/Core/src/Platform/Android/MauiScrollView.cs index ed81d7a0f8c6..444372df851b 100644 --- a/src/Core/src/Platform/Android/MauiScrollView.cs +++ b/src/Core/src/Platform/Android/MauiScrollView.cs @@ -187,7 +187,7 @@ protected override void OnLayout(bool changed, int left, int top, int right, int { base.OnLayout(changed, left, top, right, bottom); - if (_hScrollView != null && _hScrollView.Parent == this && _content != null) + if (_hScrollView?.Parent == this && _content is not null) { double scrollViewContentHeight = _content.Height; var hScrollViewHeight = bottom - top;