Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Line break mode not applying on Html Labels #13782

Open
DamienDoumer opened this issue Feb 16, 2021 · 2 comments
Open

[Bug] Line break mode not applying on Html Labels #13782

DamienDoumer opened this issue Feb 16, 2021 · 2 comments

Comments

@DamienDoumer
Copy link

DamienDoumer commented Feb 16, 2021

Description

When text is added to HTML label, if you set line break mode, it won't be applied.

Steps to Reproduce

  1. Ia simple page, add a label
    <Label x:Name="HtmlLabel" TextType="Html" WidthRequest="100" LineBreakMode="MiddleTruncation" HorizontalOptions="Start" TextColor="Black"/> <Label x:Name="HtmlLabel2" TextType="Html" WidthRequest="100" LineBreakMode="MiddleTruncation" HorizontalOptions="Start" TextColor="Black"/>

  2. Create Html text and add it to the label
    HtmlText = @" <a href=\""https://doumer.me\"">Click here aksdnf klajnsdfklansd faklsdn fasdof asdophf al;kfasdfaoisdfoasdf aosdfao</a>";
    HtmlText2 = @"<h1>Click here aksdnf klajnsdfklansd faklsdn fasdof asdophf al;kfasdfaoisdfoasdf aosdfao</h1>";
    HtmlLabel.Text = HtmlText;
    HtmlLabel2.Text = HtmlText2;

  3. Run app, and notice linebreak mode does not apply.

Expected Behavior

Line break mode should apply on HTML labels too.

Actual Behavior

LIne break mode doesn't apply on html labels

img

Basic Information

  • Version with issue: 5.0
  • Last known good version: none
  • Platform Target Frameworks:
    • iOS: All
    • Android: All
@DamienDoumer DamienDoumer added s/unverified New report that has yet to be verified t/bug 🐛 labels Feb 16, 2021
@samhouts samhouts added this to New in Triage Feb 16, 2021
@hartez hartez added a/label and removed s/unverified New report that has yet to be verified labels Feb 18, 2021
@hartez hartez added this to To do in Android Ready For Work via automation Feb 18, 2021
@hartez hartez added this to To do in iOS Ready For Work via automation Feb 18, 2021
@hartez hartez removed this from New in Triage Feb 18, 2021
@jl-mobitech
Copy link

jl-mobitech commented Jan 9, 2023

Any updates? It will become a 2 year issue next month.

@jl-mobitech
Copy link

jl-mobitech commented Jan 9, 2023

I just successfully created a workaround for now by using custom renderers @DamienDoumer, please see the attached code:

Android:

public class HtmlLabelAndroid : LabelRenderer
{
    public HtmlLabelAndroid(Context context) : base(context) { }

    protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
    {
        base.OnElementChanged(e);
        if (e.NewElement is HtmlLabel htmlLabel)
        {
            Control.Ellipsize = TextUtils.TruncateAt.End;
            Control.SetMaxLines(htmlLabel.MaxLines);
            Control.SetText(Html.FromHtml(htmlLabel.Text, FromHtmlOptions.ModeLegacy), BufferType.Normal);
        }
    }
}

iOS:

public class HtmlLabeliOS : LabelRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
    {
        base.OnElementChanged(e);
        if (e.NewElement is HtmlLabel htmlLabel)
        {

            var nsError = new NSError();
            Control.AttributedText = new NSAttributedString(htmlLabel.Text,
                new NSAttributedStringDocumentAttributes { DocumentType = NSDocumentType.HTML },
                ref nsError);
            Control.LineBreakMode = UILineBreakMode.TailTruncation;
            Control.Lines = htmlLabel.MaxLines;
        }
    }
}

Please see the attached photo (First photo is on Android, while the latter is for iOS):
image
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

No branches or pull requests

3 participants