Effect that changes Label's background does not work when the FastRenderers flag is set
#5336 aperta il 21 feb 2019
Metriche repository
- Star
- (5644 stelle)
- Metriche merge PR
- (Nessuna PR mergiata in 30 g)
Descrizione
Description
I've created an effect to show a border around many controls, everything seems good until I tested it while the FastRenderers flag is enabled, it worked for all my tests except for the Labels.
I'm creating the border by setting the TextView's background, I wasn't able to figure out the exact problem because the FastRenderers.LabelRenderer class is internal sealed and it's using the BackgroundManager which is also internal.
Steps to Reproduce
To reproduce the issue, I've modified the ShadowEffect sample project, I've just enabled the FastRenderers flag and modified the OnAttached override to set the Background instead of the ShadowLayer:
protected override void OnAttached()
{
try
{
var control = Control as Android.Widget.TextView;
var effect = (ShadowEffect)Element.Effects.FirstOrDefault(e => e is ShadowEffect);
if (effect != null)
{
Android.Graphics.Color color = effect.Color.ToAndroid();
if (!(control.Background is Android.Graphics.Drawables.GradientDrawable gradientBackground))
{
gradientBackground = new Android.Graphics.Drawables.GradientDrawable();
control.SetBackground(gradientBackground);
}
gradientBackground.SetStroke(1, color);
}
}
catch (Exception ex)
{
Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
}
}
Expected Behavior
Actual Behavior
Basic Information
- Android Target Framework: 8.1 (API 27)
- Latest Xamarin.Forms (3.5.0.129452)