0

I am struggling to find the cross-platform answer to native link detection in labels. In Android, it seems to be TextView's AutoLink, which is set up in my custom renderer subclass of LabelRenderer. But in iOS, you have to do it through UITextView's dataDetectorTypes which is the Xam.Forms equivalent of an Entry/Editor. So how do I make a Label-esque View in XF such that on Android it uses LabelRenderer but on iOS it uses EditorRenderer (multi-line support is necessary). I started to subclass a XF View and write custom bindings that would wire up to either a XF Editor on iOS or a XF Label on Android, but that just started to feel wrong.

Then I tried to just subclass Editor for both, but my attempts to make that look/behave like a static Label on Android were a mess (this has to work as a ListView DataTemplate and one thing I found odd was that it was confusing HasUnevenRows height when the ListViewCachingStrategy was set to Recycle).

I also started to do custom ViewRenderers per platform but that seemed like a total mess because you basically don't get to inherit any of the goodness that comes with LabelRenderer / EditorRenderer and you're forced to recreate it all... which I wasn't getting good results with either.

It seems like there should be an easy way in XF to support each platforms' native link detection in a single View?

dooleyo
  • 872
  • 1
  • 9
  • 13
  • 1
    Nope, Xamarin forms do not provide this feature, you should achieve it by custom renderer. https://theconfuzedsourcecode.wordpress.com/tag/xamarin-hyperlink-label/ – Leon Mar 12 '20 at 05:37
  • Thanks @LeonLu-MSFT , great work! This was one of the approaches I tried, but when doing it this way you lose all the LabelRenderer magic that Xamarin Forms has already done. I was finding myself having to reimplement the entire thing, but there were still rendering issues for my application (these are used within a DataTemplate of a ListView so I think that had something to do with it). I'll take a closer look at your code to see if it will help! – dooleyo Mar 13 '20 at 08:30
  • Do you have some update? – Leon Mar 16 '20 at 09:47

0 Answers0