diff --git a/src/HtmlLabel/HtmlLabel.Forms.Plugin.csproj b/src/HtmlLabel/HtmlLabel.Forms.Plugin.csproj index 9dbc05c..ee4968b 100644 --- a/src/HtmlLabel/HtmlLabel.Forms.Plugin.csproj +++ b/src/HtmlLabel/HtmlLabel.Forms.Plugin.csproj @@ -72,4 +72,9 @@ + + + + + diff --git a/src/HtmlLabel/Shared/HtmlLabel.cs b/src/HtmlLabel/Shared/HtmlLabel.cs index ae5bbc2..d6b3eab 100644 --- a/src/HtmlLabel/Shared/HtmlLabel.cs +++ b/src/HtmlLabel/Shared/HtmlLabel.cs @@ -88,10 +88,39 @@ public int AndroidListIndent set { SetValue(AndroidListIndentProperty, value); } } - /// - /// Fires before the open URL request is done. - /// - public event EventHandler Navigating; + /// + /// Identify the AndroidLegacyMode property. + /// + public static readonly BindableProperty IsExternalBrowserProperty = + BindableProperty.Create(nameof(IsExternalBrowserProperty), typeof(bool), typeof(HtmlLabel), default); + + /// + /// Get or set if the Android renderer separates block-level elements with blank lines. + /// + public bool IsExternalBrowser + { + get { return (bool)GetValue(IsExternalBrowserProperty); } + set { SetValue(IsExternalBrowserProperty, value); } + } + + // Declare the delegate (if using non-generic pattern). + public delegate void LinkClickEventHandler(object sender, LinkEventArgs e); + + // Declare the event. + public event LinkClickEventHandler LinkClickEvent; + + // Wrap the event in a protected virtual method + // to enable derived classes to raise the event. + public void RaiseLinkClickEvent(string link) + { + // Raise the event in a thread-safe manner using the ?. operator. + LinkClickEvent?.Invoke(this, new LinkEventArgs(link)); + } + + /// + /// Fires before the open URL request is done. + /// + public event EventHandler Navigating; /// /// Fires when the open URL request is done. diff --git a/src/HtmlLabel/Shared/LinkEventArgs.cs b/src/HtmlLabel/Shared/LinkEventArgs.cs new file mode 100644 index 0000000..bdfc4c6 --- /dev/null +++ b/src/HtmlLabel/Shared/LinkEventArgs.cs @@ -0,0 +1,10 @@ +using System; +namespace LabelHtml.Forms.Plugin.Abstractions +{ + public class LinkEventArgs + { + public LinkEventArgs(string link) { Link = link; } + public string Link { get; } + } +} + diff --git a/src/HtmlLabel/Shared/RendererHelper.cs b/src/HtmlLabel/Shared/RendererHelper.cs index 2185713..6d1c3ab 100644 --- a/src/HtmlLabel/Shared/RendererHelper.cs +++ b/src/HtmlLabel/Shared/RendererHelper.cs @@ -173,8 +173,15 @@ public static bool HandleUriClick(HtmlLabel label, string url) if (uri.IsHttp()) { - uri.LaunchBrowser(label.BrowserLaunchOptions); - result = true; + if (label.IsExternalBrowser) + { + uri.LaunchBrowser(label.BrowserLaunchOptions); + } + else + { + label.RaiseLinkClickEvent(url); + } + result = true; } else if (uri.IsEmail()) { diff --git a/src/HtmlLabel/iOS/Renderer.cs b/src/HtmlLabel/iOS/Renderer.cs index 9d5fe9d..ccbb4e5 100644 --- a/src/HtmlLabel/iOS/Renderer.cs +++ b/src/HtmlLabel/iOS/Renderer.cs @@ -75,13 +75,13 @@ private void SetText(string html) var md = new NSMutableDictionary(value); var font = md[UIStringAttributeKey.Font] as UIFont; - if (font != null) + if (Control.Font != null) { - md[UIStringAttributeKey.Font] = Control.Font.WithTraitsOfFont(font); + md[UIStringAttributeKey.Font] = Control.Font; } else { - md[UIStringAttributeKey.Font] = Control.Font; + md[UIStringAttributeKey.Font] = Control.Font.WithTraitsOfFont(font); } var foregroundColor = md[UIStringAttributeKey.ForegroundColor] as UIColor;