Custom Renderer for Span

Pedro_PazPedro_Paz Member ✭✭
edited May 2 in Xamarin.Forms

Hello devs!

I'm trying to make a Custom Renderer to ignore the android accessibility configurations in the Span Class, to not re-scale the font size.
I have made successfully renderer for the Label class but not for Span class.. Can someone help me? :D

My Label Custom Renderer is Above!

using System;
using System.ComponentModel;
using Android.Widget;
using FreePlay.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(Span), typeof(IgnoreAcessibilitySpan))]
namespace FreePlay.Droid
{

    public class IgnoreAcessibilitySpan : LabelRenderer
    {

        protected void setFontSizeAgain()
        {
            var nativeControl = (TextView)Control;
            var xfControl = Element; //e.NewElement;
            if (nativeControl != null && xfControl != null)
                nativeControl.SetTextSize(Android.Util.ComplexUnitType.Dip, xfControl.Font.ToScaledPixel());
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Label> e)
        {
            base.OnElementChanged(e);
            setFontSizeAgain();
        }

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            setFontSizeAgain();
        }
    }
}

Answers

Sign In or Register to comment.