0

We have a service that provides us with a news feed. This feed is an array of different articles. Each article has an attribute "html", which contains the content written in HTML.

Now it happens that an article contains a link Link.

In my app, which I like to write in NavtiveScript-Vue, I display the HTML code using a HtmlView component.

How do I get my app to react to the link? I already thought about the fact that the HtmlView component may emit an event when the link is clicked. Unfortunately this is not the case.

Do you have any ideas? Thank you!

  • Links like URL, Phone, Email etc., will be handled automatically. If you want to handle them on your own, either use WebView with https://github.com/Notalib/nativescript-webview-ext or you will have to natively implement the gestures in case of HtmlView - Something like https://stackoverflow.com/questions/1256887/create-tap-able-links-in-the-nsattributedstring-of-a-uilabel/28519273#28519273 – Manoj May 22 '20 at 14:15
  • Thanks for your quick reply. I'll take a look at nativescript-webview-ext. Until now i did'nt use WebView because i have to set a specific height for the component. HtmlView takes the height it needs... – Michael Löffelmann May 22 '20 at 15:45
  • Yes you will have to set a height but that should be possible by calculating the document height within WebView context and send the value back to NS and apply the height on WebView itself. – Manoj May 22 '20 at 15:58
  • Sounds like an great idea. Thank you. Then i'll check this out and post my results here. :-) – Michael Löffelmann May 22 '20 at 16:56
  • One thing: How can i calculate the height of the WebView? I tried it by injecting an js-File "window.document.body.getClientHeight" but this did not work... – Michael Löffelmann May 23 '20 at 12:55

1 Answers1

0

I would recommend to use a openURL and regex based solution.

 const regex = /(?:(?:<\/?\w+>)+|[^<>]+)/g;
 function extract(html) {
      openUrl(`mailto:${html}`);
    }

Cem Kaan
  • 2,086
  • 1
  • 24
  • 55