Xamarin.forms: Span Gesture recognizer dosen't work on righ to left text(RTL)

Created on 20 Dec 2018  路  7Comments  路  Source: xamarin/Xamarin.Forms

when we add rtl text on a label with some spans, tap gesture recognizer doesn't work.

Steps to Reproduce

   Label lblTest = new Label();
            Command command = new Command(OnTap);
            FormattedString formatted = new FormattedString();
            var a=new Span()
            {
                Text="爻賱丕賲 丿賵爻鬲 "

            };
            a.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command=command // never fired 
            });
           var b= new Span()
            {
                Text = " 禺賵亘 賲賳",

            };

            formatted.Spans.Add(a);
            formatted.Spans.Add(b);


            lblTest.FormattedText = formatted;

Expected Behavior

Tapped Command fired.

Actual Behavior

nothing happened,

Basic Information

  • Version with issue:3.4

    • IDE: visual studio 2017
rtl 3 high impact Android UWP iOS 馃崕 bug up-for-grabs

Most helpful comment

Yep. LTR works. RTL no works.

App71.zip

All 7 comments

Yep. LTR works. RTL no works.

App71.zip

Please fix this issue as my application will be nothing without this feature. It happens on iOS and UWP as well.

Same issue occurred with me. I split a text into three spans, first normal Arabic text, second normal text with blue color, and the third was normal. When tapping the blue text, the command executes as if I tapped on the first span. Is there any workaround for this problem?

Any update on this issue?

@spozdbpc
My problem was that I need a hyperlinks. so, I made a workaround to solve this problem by creating a custom renderers

PCL
public class LinkLabel : Label {}

iOS

 public class LinkLabelRenderer : ViewRenderer<LinkLabel, UITextView>
    {
        protected override void OnElementChanged(ElementChangedEventArgs<LinkLabel> e)
        {
            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    SetNativeControl(new UITextView());
                }

                UpdateText();
            }

            base.OnElementChanged(e);
        }

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

            if (e.PropertyName == nameof(LinkLabel.Text))
            {
                UpdateText();
            }
        }

        void UpdateText()
        {
            if (string.IsNullOrWhiteSpace(Element?.Text))
            {
                Control.Text = string.Empty;
                return;
            }
            var text = $"<style>body{{font-size:{Element.FontSize}px;}}</style>" + Element.Text;
            NSError error = null;
            Control.BackgroundColor = Color.Transparent.ToUIColor();
            Control.AttributedText = new NSAttributedString(NSData.FromString(text, NSStringEncoding.Unicode),
                                                            new NSAttributedStringDocumentAttributes { DocumentType = NSDocumentType.HTML },
                                                            ref error);
            Control.Editable = false;
            Control.ScrollEnabled = false;
            Control.ShouldInteractWithUrl += delegate { return true; };
        }
    }

Android

public class LinkLabelRenderer : LabelRenderer
    {
        public LinkLabelRenderer(Context context)
            : base(context)
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);

            if (Control != null && e.NewElement != null)
            {
                UpdateText();
            }
        }

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

            if (e.PropertyName == nameof(LinkLabel.Text))
            {
                UpdateText();
            }
        }

        void UpdateText()
        {
            if (string.IsNullOrWhiteSpace(Element?.Text))
            {
                Control.Text = string.Empty;
                return;
            }

            Control.TextFormatted = Html.FromHtml(Element.Text, FromHtmlOptions.ModeCompact);
            Control.MovementMethod = Android.Text.Method.LinkMovementMethod.Instance;
        }
    }

Hope this helps you

Any update on this issue?

any update? , I this is second app I face this problem and do a stupid workaround and didn't get what I want, please any help

Was this page helpful?
0 / 5 - 0 ratings