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

Commit

Permalink
Fix Frame black background issue (#14623)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz committed Sep 17, 2021
1 parent 4972ef0 commit 13cfd79
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8" ?>
<local:TestContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Frame Backgrund Issue" xmlns:local="using:Xamarin.Forms.Controls"
x:Class="Xamarin.Forms.Controls.Issues.FrameBackgroundIssue">
<ScrollView>
<StackLayout
Padding="12">
<Frame
HasShadow="False"
WidthRequest="150"
BackgroundColor="LightGray"
BorderColor="DarkGreen"
CornerRadius="0"
Padding="0">
<StackLayout>
<BoxView
BackgroundColor="GreenYellow" />
<Label
Margin="8"
Text="Frame using BackgroundColor"
TextColor="Black" />
</StackLayout>
</Frame>
<Frame
HasShadow="False"
WidthRequest="150"
BackgroundColor="LightGray"
BorderColor="DarkGreen"
CornerRadius="{Binding Source={x:Reference CornerRadiusSlider}, Path=Value}"
Padding="0">
<StackLayout>
<BoxView
BackgroundColor="GreenYellow" />
<Label
Margin="8"
Text="Frame using BackgroundColor"
TextColor="Black" />
</StackLayout>
</Frame>
<Frame
HasShadow="False"
WidthRequest="150"
Background="LightGray"
BorderColor="DeepPink"
CornerRadius="0"
Padding="0">
<StackLayout>
<BoxView
Background="LightPink" />
<Label
Margin="8"
Text="Frame using Background"
TextColor="Black" />
</StackLayout>
</Frame>
<Frame
HasShadow="False"
WidthRequest="150"
Background="LightGray"
BorderColor="DeepPink"
CornerRadius="{Binding Source={x:Reference CornerRadiusSlider}, Path=Value}"
Padding="0">
<StackLayout>
<BoxView
Background="LightPink" />
<Label
Margin="8"
Text="Frame using Background"
TextColor="Black" />
</StackLayout>
</Frame>
<Label
FontSize="Micro"
Text="Frame CornerRadius"/>
<Slider
x:Name="CornerRadiusSlider"
Minimum="0"
Maximum="48"
Value="12"/>
</StackLayout>
</ScrollView>
</local:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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, 0,
"[Bug] Frame Background not working",
PlatformAffected.Android)]
public partial class FrameBackgroundIssue : TestContentPage
{
public FrameBackgroundIssue()
{
#if APP
InitializeComponent();
#endif
}

protected override void Init()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue13726.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11795.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14286.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FrameBackgroundIssue.xaml.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down Expand Up @@ -2220,6 +2221,9 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue14286.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)FrameBackgroundIssue.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla27417Xaml.xaml">
Expand Down
18 changes: 6 additions & 12 deletions Xamarin.Forms.Platform.Android/FastRenderers/FrameRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using Android.Content;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Graphics.Drawables.Shapes;
using Android.Views;
using AndroidX.CardView.Widget;
Expand All @@ -22,7 +23,7 @@ public class FrameRenderer : CardView, IVisualElementRenderer, IViewRenderer, IT
bool _hasLayoutOccurred;
bool _disposed;
Frame _element;
GradientStrokeDrawable _backgroundDrawable;
GradientDrawable _backgroundDrawable;

VisualElementPackager _visualElementPackager;
VisualElementTracker _visualElementTracker;
Expand Down Expand Up @@ -176,10 +177,8 @@ protected virtual void OnElementChanged(ElementChangedEventArgs<Frame> e)
if (e.NewElement != null)
{
this.EnsureId();
_backgroundDrawable = new GradientStrokeDrawable
{
Shape = new RectShape()
};

_backgroundDrawable = new GradientDrawable();
this.SetBackground(_backgroundDrawable);

if (_visualElementTracker == null)
Expand Down Expand Up @@ -299,10 +298,7 @@ void UpdateBackground()
_backgroundDrawable = null;
this.SetBackground(null);

_backgroundDrawable = new GradientStrokeDrawable
{
Shape = new RectShape()
};
_backgroundDrawable = new GradientDrawable();

this.SetBackground(_backgroundDrawable);
UpdateBorderColor();
Expand All @@ -318,7 +314,7 @@ void UpdateBackground()
_height = Control.Height;
_width = Control.Width;

_backgroundDrawable.UpdateBackground(background);
_backgroundDrawable.UpdateBackground(background, _height, _width);
}
}

Expand Down Expand Up @@ -357,9 +353,7 @@ void UpdateCornerRadius()
return;

if (_defaultCornerRadius == -1f)
{
_defaultCornerRadius = Radius;
}

float cornerRadius = Element.CornerRadius;

Expand Down

0 comments on commit 13cfd79

Please sign in to comment.