Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Make sure ScrollViewRenderer on Android is resolving layout changes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez authored Jan 24, 2022
1 parent 8f765bd commit 3620bea
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Xamarin.Forms.CustomAttributes;

namespace Xamarin.Forms.Controls.Issues
{
[Issue(IssueTracker.Github, 15066, "StackLayout's layout inside ScrollView is not updated properly when adding children",
PlatformAffected.Android)]
public class Issue15066 : TestContentPage
{
protected override void Init()
{
var instructions = new Label
{
BackgroundColor = Color.AntiqueWhite,
Padding = 3,
Text = "Tap the 'Add' button until the added items are past the bottom of the screen." +
" Then scroll down - if there is any blue visible at the bottom, this test has failed."
};

var scrollView = new ScrollView() { BackgroundColor = Color.DarkBlue };

var layout = new StackLayout() { BackgroundColor = Color.DarkGreen };

var button = new Button() { Text = "Add" };

button.Clicked += (sender, args) => {
layout.Children.Add(new StackLayout() { BackgroundColor = Color.Gray, HeightRequest = 40.0 });
};

layout.Children.Add(instructions);
layout.Children.Add(button);

for (int n = 0; n < 8; n++)
{
layout.Children.Add(new StackLayout() { BackgroundColor = Color.Gray, HeightRequest = 40.0 });
}

scrollView.Content = layout;

Content = scrollView;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue14801.xaml.cs">
<DependentUpon>Issue14801.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue15066.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8804.xaml.cs">
<DependentUpon>Issue8804.xaml</DependentUpon>
</Compile>
Expand Down
10 changes: 10 additions & 0 deletions Xamarin.Forms.Platform.Android/Renderers/ScrollViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ protected override void OnLayout(bool changed, int left, int top, int right, int
_checkedForRtlScroll = true;
}

protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if (Element is Layout layout)
{
layout.ResolveLayoutChanges();
}

base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
}

protected override void OnScrollChanged(int l, int t, int oldl, int oldt)
{
_checkedForRtlScroll = true;
Expand Down

0 comments on commit 3620bea

Please sign in to comment.