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

Commit

Permalink
[Core] AbsoluteLayout content now fills all available space on Androi…
Browse files Browse the repository at this point in the history
…d devices (#1761)

* Removed rounding in AbsoluteLayout to ensure Android devices with certain sizes can still use proportional sizes to fill the device screen.

* doc updates
  • Loading branch information
PureWeen authored and Jason Smith committed Feb 7, 2018
1 parent 6d5d4a3 commit 7e387eb
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System;
using System.Threading.Tasks;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 40092, "Ensure android devices with fractional scale factors (3.5) don't have a white line around the border", PlatformAffected.Android)]
public class Bugzilla40092 : TestContentPage
{
protected override void Init()
{
AbsoluteLayout mainLayout = new AbsoluteLayout()
{
BackgroundColor = Color.White
};


// The root page of your application
var thePage = new ContentView
{
BackgroundColor = Color.Red,
Content = mainLayout
};

BoxView view = new BoxView()
{
Color = Color.Black
};

mainLayout.Children.Add(view, new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All);
Content = thePage;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla58779.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51825.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla31688.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40092.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down
8 changes: 8 additions & 0 deletions Xamarin.Forms.Core.UnitTests/AbsoluteLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ namespace Xamarin.Forms.Core.UnitTests
[TestFixture]
public class AbsoluteLayoutTests : BaseTestFixture
{
[SetUp]
public override void Setup()
{
base.Setup();
var mockDeviceInfo = new TestDeviceInfo();
Device.Info = mockDeviceInfo;
}


[Test]
public void Constructor ()
Expand Down
8 changes: 4 additions & 4 deletions Xamarin.Forms.Core/AbsoluteLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static Rectangle ComputeLayoutForRegion(View view, Size region)

if (widthIsProportional)
{
result.Width = Math.Round(region.Width * bounds.Width);
result.Width = Device.Info.DisplayRound(region.Width * bounds.Width);
}
else if (bounds.Width != AutoSize)
{
Expand All @@ -241,7 +241,7 @@ static Rectangle ComputeLayoutForRegion(View view, Size region)

if (heightIsProportional)
{
result.Height = Math.Round(region.Height * bounds.Height);
result.Height = Device.Info.DisplayRound(region.Height * bounds.Height);
}
else if (bounds.Height != AutoSize)
{
Expand Down Expand Up @@ -273,7 +273,7 @@ static Rectangle ComputeLayoutForRegion(View view, Size region)

if (xIsProportional)
{
result.X = Math.Round((region.Width - result.Width) * bounds.X);
result.X = Device.Info.DisplayRound((region.Width - result.Width) * bounds.X);
}
else
{
Expand All @@ -282,7 +282,7 @@ static Rectangle ComputeLayoutForRegion(View view, Size region)

if (yIsProportional)
{
result.Y = Math.Round((region.Height - result.Height) * bounds.Y);
result.Y = Device.Info.DisplayRound((region.Height - result.Height) * bounds.Y);
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions Xamarin.Forms.Core/DeviceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public DeviceOrientation CurrentOrientation
}
}

public virtual double DisplayRound(double value) =>
Math.Round(value);

public abstract Size PixelScreenSize { get; }

public abstract Size ScaledScreenSize { get; }
Expand Down
4 changes: 4 additions & 0 deletions Xamarin.Forms.Platform.Android/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ public override double ScalingFactor
get { return _scalingFactor; }
}


public override double DisplayRound(double value) =>
Math.Round(ScalingFactor * value) / ScalingFactor;

protected override void Dispose(bool disposing)
{
if (_disposed)
Expand Down
20 changes: 20 additions & 0 deletions docs/Xamarin.Forms.Core/Xamarin.Forms.Internals/DeviceInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="DisplayRound">
<MemberSignature Language="C#" Value="public virtual double DisplayRound (double value);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance float64 DisplayRound(float64 value) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Double</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="value" Type="System.Double" />
</Parameters>
<Docs>
<param name="value">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Dispose">
<MemberSignature Language="C#" Value="public void Dispose ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance void Dispose() cil managed" />
Expand Down

0 comments on commit 7e387eb

Please sign in to comment.