Exemplo n.º 1
0
 protected override bool NavigateToUrl(NSUrl url)
 {
     if (url == null)
     {
         throw new ArgumentNullException(nameof(url));
     }
     // Try to handle uri, if it can't be handled, fall back to IOS his own handler.
     return(!RendererHelper.HandleUriClick(Element, url.AbsoluteString));
 }
Exemplo n.º 2
0
        public static void HandleLinkTap(this UILabel control, HtmlLabel element)
        {
            void TapHandler(UITapGestureRecognizer tap)
            {
                var detectedUrl = DetectTappedUrl(tap, (UILabel)tap.View);

                RendererHelper.HandleUriClick(element, detectedUrl);
            }

            var tapGesture = new UITapGestureRecognizer(TapHandler);

            control.AddGestureRecognizer(tapGesture);
            control.UserInteractionEnabled = true;
        }
Exemplo n.º 3
0
 public override void OnClick(Android.Views.View widget)
 {
     RendererHelper.HandleUriClick(_label, _span.URL);
 }
Exemplo n.º 4
0
 protected override bool NavigateToUrl(NSUrl url)
 {
     // Try to handle uri, if it can't be handled, fall back to IOS his own handler.
     return(!RendererHelper.HandleUriClick(Element, url.AbsoluteString));
 }
        private static void ParseText(XElement element, InlineCollection inlines, HtmlLabel label)
        {
            if (element == null)
            {
                return;
            }

            InlineCollection currentInlines = inlines;
            var elementName = element.Name.ToString().ToUpperInvariant();

            switch (elementName)
            {
            case _elementA:
                var        link         = new Hyperlink();
                XAttribute href         = element.Attribute("href");
                var        unescapedUri = Uri.UnescapeDataString(href?.Value);
                if (href != null)
                {
                    try
                    {
                        link.NavigateUri = new Uri(unescapedUri);
                    }
                    catch (FormatException) { /* href is not valid */ }
                }
                link.Click += (sender, e) =>
                {
                    sender.NavigateUri = null;
                    RendererHelper.HandleUriClick(label, unescapedUri);
                };
                if (!label.LinkColor.IsDefault)
                {
                    link.Foreground = label.LinkColor.ToBrush();
                }
                if (!label.UnderlineText)
                {
                    link.UnderlineStyle = UnderlineStyle.None;
                }
                inlines.Add(link);
                currentInlines = link.Inlines;
                break;

            case _elementB:
            case _elementStrong:
                var bold = new Bold();
                inlines.Add(bold);
                currentInlines = bold.Inlines;
                break;

            case _elementI:
            case _elementEm:
                var italic = new Italic();
                inlines.Add(italic);
                currentInlines = italic.Inlines;
                break;

            case _elementU:
                var underline = new Underline();
                inlines.Add(underline);
                currentInlines = underline.Inlines;
                break;

            case _elementBr:
                inlines.Add(new LineBreak());
                break;

            case _elementP:
                // Add two line breaks, one for the current text and the second for the gap.
                if (AddLineBreakIfNeeded(inlines))
                {
                    inlines.Add(new LineBreak());
                }

                var paragraphSpan = new Span();
                inlines.Add(paragraphSpan);
                currentInlines = paragraphSpan.Inlines;
                break;

            case _elementLi:
                inlines.Add(new LineBreak());
                inlines.Add(new Run {
                    Text = " • "
                });
                break;

            case _elementUl:
            case _elementDiv:
                _ = AddLineBreakIfNeeded(inlines);
                var divSpan = new Span();
                inlines.Add(divSpan);
                currentInlines = divSpan.Inlines;
                break;
            }
            foreach (XNode node in element.Nodes())
            {
                if (node is XText textElement)
                {
                    currentInlines.Add(new Run {
                        Text = textElement.Value
                    });
                }
                else
                {
                    ParseText(node as XElement, currentInlines, label);
                }
            }

            // Add newlines for paragraph tags
            if (elementName == "ElementP")
            {
                currentInlines.Add(new LineBreak());
            }
        }