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

Commit

Permalink
Backport #11032 to 4.6.0 (#11040)
Browse files Browse the repository at this point in the history
* [iOS] Fix BackgroundColor issue with Frame (#11032)

* Fixed regression issue with Frame

* Removed wrong set of BackgroundColor to null

* Fix FrameRenderer background;
Make Frame CornerRadius test actually count;
Fix Frame BackgroundColor consistency test;

* Make the radius bigger to get the shadow out of the way

Co-authored-by: E.Z. Hart <[email protected]>

fixes #11031

* Remove ignore attribute now that 9625 is fixed

Co-authored-by: Javier Suárez <[email protected]>
Co-authored-by: E.Z. Hart <[email protected]>
  • Loading branch information
3 people authored Jun 14, 2020
1 parent 474d348 commit 1c5aec6
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.Frame)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 11031,
"[Bug] Regression in 4.7-pre4: Frames are broken",
PlatformAffected.Android)]
public class Issue11031 : TestContentPage
{
public Issue11031()
{
}

protected override void Init()
{
Title = "Issue 11031";

var layout = new StackLayout();

var frame = new Frame
{
BackgroundColor = Color.Red,
BorderColor = Color.Black,
CornerRadius = 24,
Margin = 12
};

var label = new Label
{
HorizontalTextAlignment = TextAlignment.Center,
TextColor = Color.White,
Text = "Issue 11031"
};

frame.Content = label;

layout.Children.Add(frame);

Content = layout;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue9555.xaml.cs">
<DependentUpon>Issue9555.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue11031.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.Forms.Platform.iOS.UnitTests/BackgroundColorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public async Task BackgroundColorConsistent(VisualElement element)
public async Task FrameBackgroundColorConsistent()
{
var frame = new Frame { BackgroundColor = Color.AliceBlue };
var expected = frame.BackgroundColor.ToUIColor();
var actual = await GetRendererProperty(frame, r => r.NativeView.BackgroundColor);
Assert.That(actual, Is.EqualTo(expected));
var expectedColor = frame.BackgroundColor.ToUIColor();
var screenshot = await GetRendererProperty(frame, (ver) => ver.NativeView.ToBitmap(), requiresLayout: true);
screenshot.AssertColorAtCenter(expectedColor);
}

[Test, Category("BackgroundColor"), Category("Label")]
Expand Down
3 changes: 1 addition & 2 deletions Xamarin.Forms.Platform.iOS.UnitTests/CornerRadiusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public async Task ButtonCornerRadius()
}

[Test, Category("CornerRadius"), Category("Frame")]
[Ignore("Will not pass until https://github.com/xamarin/Xamarin.Forms/issues/9265 is fixed")]
public async Task FrameCornerRadius()
{
var backgroundColor = Color.CadetBlue;
Expand All @@ -47,7 +46,7 @@ public async Task FrameCornerRadius()
{
HeightRequest = 100,
WidthRequest = 200,
CornerRadius = 15,
CornerRadius = 40,
BackgroundColor = backgroundColor,
BorderColor = Color.Brown,
Content = new Label { Text = "Hey" }
Expand Down
5 changes: 5 additions & 0 deletions Xamarin.Forms.Platform.iOS/Renderers/FrameRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ public virtual void SetupLayer()
if (Element.BackgroundColor == Color.Default)
_actualView.Layer.BackgroundColor = ColorExtensions.BackgroundColor.CGColor;
else
{
// BackgroundColor gets set on the base class too which messes with
// the corner radius, shadow, etc. so override that behaviour here
BackgroundColor = UIColor.Clear;
_actualView.Layer.BackgroundColor = Element.BackgroundColor.ToCGColor();
}

if (Element.BorderColor == Color.Default)
_actualView.Layer.BorderColor = UIColor.Clear.CGColor;
Expand Down

0 comments on commit 1c5aec6

Please sign in to comment.