summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2016-10-25 12:07:57 -0500
committerRui Marinho <me@ruimarinho.net>2016-10-25 18:07:57 +0100
commitb4a46d482f4b511de7e829f1cfe16aa81057560a (patch)
tree6d3323d136f973b41e3c9f555adf6f1c60afec71
parent6196407f8924463e526bc96f6855560954d9d2e0 (diff)
downloadxamarin-forms-b4a46d482f4b511de7e829f1cfe16aa81057560a.tar.gz
xamarin-forms-b4a46d482f4b511de7e829f1cfe16aa81057560a.tar.bz2
xamarin-forms-b4a46d482f4b511de7e829f1cfe16aa81057560a.zip
ScrollView should account for Content margin (#392)
* ScrollView should account for Content margin * Unit tests for content margin
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41418.cs30
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Core.UnitTests/ScrollViewUnitTests.cs54
-rw-r--r--Xamarin.Forms.Core/ScrollView.cs4
4 files changed, 87 insertions, 2 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41418.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41418.cs
new file mode 100644
index 00000000..adda09ab
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41418.cs
@@ -0,0 +1,30 @@
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 41418, "Margin inside ScrollView not working properly", PlatformAffected.All)]
+ public class Bugzilla41418 : TestContentPage
+ {
+ protected override void Init()
+ {
+ Content = new ScrollView()
+ {
+ BackgroundColor = Color.Yellow,
+ Content = new BoxView
+ {
+ Margin = 100,
+ WidthRequest = 500,
+ HeightRequest = 800,
+ BackgroundColor = Color.Red
+ }
+ };
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 07b8d7b4..0e1f0297 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -114,6 +114,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41078.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40998.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41205.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41418.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41424.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42069.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42069_Page.xaml.cs">
diff --git a/Xamarin.Forms.Core.UnitTests/ScrollViewUnitTests.cs b/Xamarin.Forms.Core.UnitTests/ScrollViewUnitTests.cs
index 066d4e5d..0ed525c0 100644
--- a/Xamarin.Forms.Core.UnitTests/ScrollViewUnitTests.cs
+++ b/Xamarin.Forms.Core.UnitTests/ScrollViewUnitTests.cs
@@ -399,5 +399,59 @@ namespace Xamarin.Forms.Core.UnitTests
Assert.That (scroll.ScrollX, Is.EqualTo (100));
Assert.That (scroll.ScrollY, Is.EqualTo (100));
}
+
+ [Test]
+ public void TestScrollContentMarginHorizontal()
+ {
+ View view = new View { IsPlatformEnabled = true, Margin = 100, WidthRequest = 100, HeightRequest = 100 };
+
+ var scroll = new ScrollView
+ {
+ Content = view,
+ Orientation = ScrollOrientation.Horizontal,
+ Platform = new UnitPlatform()
+ };
+ scroll.Layout(new Rectangle(0, 0, 100, 100));
+
+ Assert.AreEqual(new Size(300, 100), scroll.ContentSize);
+ Assert.AreEqual(100, scroll.Height);
+ Assert.AreEqual(100, scroll.Width);
+ }
+
+ [Test]
+ public void TestScrollContentMarginVertical()
+ {
+ View view = new View { IsPlatformEnabled = true, Margin = 100, WidthRequest = 100, HeightRequest = 100 };
+
+ var scroll = new ScrollView
+ {
+ Content = view,
+ Orientation = ScrollOrientation.Vertical,
+ Platform = new UnitPlatform()
+ };
+ scroll.Layout(new Rectangle(0, 0, 100, 100));
+
+ Assert.AreEqual(new Size(100, 300), scroll.ContentSize);
+ Assert.AreEqual(100, scroll.Height);
+ Assert.AreEqual(100, scroll.Width);
+ }
+
+ [Test]
+ public void TestScrollContentMarginBiDirectional()
+ {
+ View view = new View { IsPlatformEnabled = true, Margin = 100, WidthRequest = 100, HeightRequest = 100 };
+
+ var scroll = new ScrollView
+ {
+ Content = view,
+ Orientation = ScrollOrientation.Both,
+ Platform = new UnitPlatform()
+ };
+ scroll.Layout(new Rectangle(0, 0, 100, 100));
+
+ Assert.AreEqual(new Size(300, 300), scroll.ContentSize);
+ Assert.AreEqual(100, scroll.Height);
+ Assert.AreEqual(100, scroll.Width);
+ }
}
}
diff --git a/Xamarin.Forms.Core/ScrollView.cs b/Xamarin.Forms.Core/ScrollView.cs
index 13ae6ad9..2c1f070d 100644
--- a/Xamarin.Forms.Core/ScrollView.cs
+++ b/Xamarin.Forms.Core/ScrollView.cs
@@ -268,7 +268,7 @@ namespace Xamarin.Forms
double GetMaxHeight(double height)
{
- return Math.Max(height, _content.Bounds.Bottom + Padding.Bottom);
+ return Math.Max(height, _content.Bounds.Top + Padding.Top + _content.Bounds.Bottom + Padding.Bottom);
}
static double GetMaxHeight(double height, SizeRequest size)
@@ -278,7 +278,7 @@ namespace Xamarin.Forms
double GetMaxWidth(double width)
{
- return Math.Max(width, _content.Bounds.Right + Padding.Right);
+ return Math.Max(width, _content.Bounds.Left + Padding.Left + _content.Bounds.Right + Padding.Right);
}
static double GetMaxWidth(double width, SizeRequest size)