xamarin/Xamarin.Forms

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

オープン

#5,336 opened on 2019/02/21

 (4 件のコメント) (0 件のリアクション) (0 人の担当者)C# (1,926 件のフォーク)batch import
4.0.0a/fastrendererse/3 :clock3:help wantedinactivep/Androidt/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

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

コントリビューターガイド