xamarin/Xamarin.Forms

Effect that changes Label's background does not work when the FastRenderers flag is set

Ouverte

#5 336 ouverte le 21 févr. 2019

 (4 commentaires) (0 réaction) (0 personne assignée)C# (1 926 forks)batch import
4.0.0a/fastrendererse/3 :clock3:help wantedinactivep/Androidt/bug :bug:up-for-grabs

Métriques du dépôt

Stars
 (5 644 étoiles)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

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)

Reproduction Link

Issue.zip

Guide contributeur