matteobortolazzo / HtmlLabelPlugin

Use this Xamarin.Forms plugin to display HTML content into a label.
MIT License
137 stars 32 forks source link

Tapping on iOS 12 doesn't work properly with multiple line labels #106

Closed dbard closed 4 years ago

dbard commented 4 years ago

If the user taps on a link appearing after the first line of a multiple line label, the link doesn't open. I was able to reproduce this using the test project with the Nuget.

I've put up a pull request with what I think is a good solution. https://github.com/matteobortolazzo/HtmlLabelPlugin/pull/105

And... thank you for your work on this Nuget!!

IeuanWalker commented 4 years ago

@matteobortolazzo is this fixed? I have a bug in our app that neds fixing today, if there is a fix any chance of a beta or preview release today?

matteobortolazzo commented 4 years ago

@IeuanWalker I cannot test it so I trust @dbard PR Now 4.1.3 is releasing

IeuanWalker commented 4 years ago

@matteobortolazzo thanks for releasing it so quickly. Unfortunately version 4.1.3 still doesn't work for me. I'm using a iOS 13.5 emulator.

matteobortolazzo commented 4 years ago

I am sorry to head that!

Unfortunately I cannot work on that right now.

Can you please try version 5 (alpha) then?

IeuanWalker commented 4 years ago

@matteobortolazzo i can confirm link and phone numbers are working, but email link isn't. Also seams to have an issue with scrolling.

The control is wrapped in a scrollview, but is only scrollable when the view is refreshed with hot reload. Wasnt an issue on older versions

matteobortolazzo commented 4 years ago

Got it, can add those issues as comments in pr #104 please?

IeuanWalker commented 4 years ago

@matteobortolazzo done. As i need this fixed my self are you ok with me messing around with that PR? cant promise anything though.

matteobortolazzo commented 4 years ago

Sure, help is always welcome :) thanks

dbard commented 4 years ago

Note that the code I provided was meant to address that there was some unnecessary math being performed to determine total characters which wasn't necessary. It only addressed where on the screen a tap occurred, nothing to do with what happens within the library after the tap was correctly observed.

matteobortolazzo commented 4 years ago

@dbard sure, don't worry, your update is still valid! Thanks again

IeuanWalker commented 4 years ago

@matteobortolazzo @dbard The scroll issue seams to happen if the html is set after the the page is loaded. In my project I have a markdown file embedded in the project, and in the OnAppearing of the page i read the file, and convert it too html, then set the text on HtmlLabel. I've replicated the issue here - https://github.com/IeuanWalker/HtmlLabelPlugin/tree/Bug/Scrollview

The scrollview works just text is cut off

And this is the error that I'm getting when clicking the email link (also replicated in the above repo)

2020-06-24 18:02:29.112257+0100 HtmlLabel.Forms.Plugin.Tests.App.iOS[62636:1277100] -canOpenURL: failed for URL: "mailto:" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
[0:] Specified method is not supported.:             ERROR: 
2020-06-24 18:02:29.121559+0100 HtmlLabel.Forms.Plugin.Tests.App.iOS[62636:1277258] [default] Failed to open URL mailto:github@github.com?subject=Awesome&body=Awesome%20plugin: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=247, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}
IeuanWalker commented 4 years ago

@matteobortolazzo Update

I think the scrolling issue is do to this issue - https://github.com/xamarin/Xamarin.Forms/issues/1332 For now I've moved the method call from the OnAppearing to the page constructor before the InitializeComponent(); call and all seams fine. Only reason it was in the OnAppearing was because it was using async methods to handle error messages + PopAsync. But I've updated it so it catches the error in the constructor and in the OnAppearing if the text is null then it show the error message and pops the page.

So only issue I have now is around email links, but its not going to stop us releasing with it not working. So ill stick to v5 alpha for now,

matteobortolazzo commented 4 years ago

Got it, glad to hear. About emails, it looks like it is a Xamarin.Essentials issue, do you need to whitelist emails in the Info.plist maybe?

EDIT: I think public static bool IsEmail(this Uri uri) => uri.MatchSchema("mailto") is not returning True, do you mind debug it please?

EDIT 2: Maybe I should have added Unit Tests for those extension methods.

IeuanWalker commented 4 years ago

@matteobortolazzo Ye sure ill give it a test in a bit

IeuanWalker commented 4 years ago

@matteobortolazzo

I use a simulator 90%, but turns out the Xamarin.Essentials email isn't supported on iOS simulators. From the docs - 'To use the Email API on iOS you must run it on a physical device, else an exception will be thrown.' https://docs.microsoft.com/en-us/xamarin/essentials/email?tabs=ios

Tested my project on a physical device and I'm getting a 'NullReferenceException' when clicking on an email link. I've imported the HtmlLabel project into mine (so I don't have to create provisioning profile to test on a physical device) and its throwing the error here - image

Updating the code to this fixes it - image Do you reckon you could do a another Alpha release with this fix today?

IeuanWalker commented 4 years ago

@matteobortolazzo PR created - #108

matteobortolazzo commented 4 years ago

v5 Released