nativescript-community / ui-label

Alternative to the built-in NativeScript Label but with better performance and additional features such as HTML rendering and more.
Apache License 2.0
19 stars 7 forks source link

registerElement call not mentioned in the docs #5

Closed AnthonyLenglet closed 4 years ago

AnthonyLenglet commented 4 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.


- `tns run ios`

### Is there any code involved? 

I used the basic template and added a simple label component with the html attribute
farfromrefug commented 4 years ago

@AnthonyLenglet cant help you without a sample or with Angular. However your code works without any issue in the demo-vue app from this repo. So i think the error must come either from angular or from your setup.

AnthonyLenglet commented 4 years ago

@AnthonyLenglet cant help you without a sample or with Angular. However your code works without any issue in the demo-vue app from this repo. So i think the error must come either from angular or from your setup.

Just tested the exact same way using the tns-template-blank template instead, so it doesn't work on my end with the xml version either, its super odd...

anything particular setup wise that could cause this, or is it too broad ?

AnthonyLenglet commented 4 years ago

tried doing this in home-page.js in the blank XML template

console.log(htmlLabel.buildHTMLString({
    text: 'Hello <strong>World</strong>!'
  }));

and it did seem to work: image

AnthonyLenglet commented 4 years ago

Edit: while this does work, this removes all colors from the current labels

<HTMLLabel [html]="'Hello <b>world</b>!'"></HTMLLabel>
<Label class="h3 m-t-20 m-b-25 font-weight-medium">
  <FormattedString>
    <Span text="Hello "></Span>
    <Span class="text-primary" text="world"></Span>
    <Span text="!"></Span>
 </FormattedString>
</Label>

image

In this exemple, the word 'world' in the second text should be green, removing the plugin fixes this issue


Got it working ! 😄

In the vue demo app, this part is done

registerElement('HTMLLabel', () => require('nativescript-htmllabel').Label);

turns out you also have to do it in order to get it working in angular

did it in app.module.ts, can be done in a single component if it is only used there

import { registerElement } from "@nativescript/angular";
registerElement('HTMLLabel', () => require('nativescript-htmllabel').Label);
<StackLayout>
    <Label text="Hello <strong>World</strong>!"></Label>
    <HTMLLabel html="Hello <strong>World</strong>!"></HTMLLabel>
    <Label text="Hello ?"></Label>
</StackLayout>

only thing I am not sure about though: is it supposed to be in times new roman ? I'm guessing it is since its the default html font ?

image

farfromrefug commented 4 years ago

Ok so yes you need to register the comp :D You were using N one, thus the no rendering... About the font, yes and no ... Depends on your N version and a few other things. The best thing would be to force the font for all Labels