Skip to content

Commit fa1a166

Browse files
committed
Merge branch 'master' of github.com:Akylas/nativescript-label
2 parents 38d4bd0 + b4cd670 commit fa1a166

File tree

1 file changed

+128
-13
lines changed

1 file changed

+128
-13
lines changed

README.md

Lines changed: 128 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,161 @@
11
# NativeScript Label widget
2+
23
[![npm downloads](https://img.shields.io/npm/dm/nativescript-htmllabel.svg)](https://www.npmjs.com/package/nativescript-htmllabel)
34
[![npm downloads](https://img.shields.io/npm/dt/nativescript-htmllabel.svg)](https://www.npmjs.com/package/nativescript-htmllabel)
45
[![npm](https://img.shields.io/npm/v/nativescript-htmllabel.svg)](https://www.npmjs.com/package/nativescript-htmllabel)
56

67
A NativeScript Label widget. It is a direct replacement for the {N} Label widget.
78

89
## Installation
10+
911
Run the following command from the root of your project:
1012

11-
`tns plugin add nativescript-htmllabel`
13+
`tns plugin add @nativescript-community/ui-label`
1214

1315
This command automatically installs the necessary files, as well as stores nativescript-htmllabel as a dependency in your project's package.json file.
1416

1517
## Configuration
16-
It works exactly the same way as the {N} plugin. However it adds a few improvements
1718

19+
It works exactly the same way as the {N} plugin. However it adds a few improvements
1820

1921
## iOS Performances
22+
2023
On iOS generating html string can be slow using the system way.
2124
You can enable `DTCoreText` to make it faster.
2225

23-
* add pod `DTCoreText` in your app Podfile at `App_Resources/ios`
26+
- add pod `DTCoreText` in your app Podfile at `App_Resources/ios`
27+
2428
```
2529
pod 'DTCoreText'
2630
```
27-
* enable it in your `app.(js|ts)` (as soon as possible)
31+
32+
- enable it in your `app.(js|ts)` (as soon as possible)
33+
2834
```javascript
2935
require('nativescript-htmlabel').enableIOSDTCoreText();
3036
```
3137

38+
### Angular
39+
40+
```typescript
41+
import { registerElement } from '@nativescript/angular';
42+
43+
registerElement('HTMLLabel', () => require('@nativescript-community/ui-label').Label);
44+
```
45+
46+
```html
47+
<!-- Normal Label Usage -->
48+
<HTMLLabel html="<b>Hello, I am BOLD!></b>" fontFamily="OpenSans" fontSize="16" margin="2 5 5 5" textWrap="true"></HTMLLabel>
49+
50+
<!-- Clickable Link Usage -->
51+
<HTMLLabel
52+
[html]="someBindedUrl"
53+
linkColor="#336699"
54+
linkUnderline="true"
55+
(linkTap)="onLinkTap($event)"
56+
fontFamily="OpenSans"
57+
fontSize="16"
58+
margin="2 5 5 5"
59+
textWrap="true"
60+
></HTMLLabel>
61+
```
62+
63+
```typescript
64+
import { Utils } from '@nativescript/core';
65+
66+
export someComponentClass() {
67+
someBindedUrl = '<a href=\"https://youtube.com\">Open Youtube.com</a>'
68+
69+
// Event binded to the linkTap function on the HTMLLabel
70+
onLinkTap(args) {
71+
const link = args.link;
72+
// expected to be https://youtube.com from the binded `<a>` tag href value
73+
// be sure to encodeURIComponent of any query string parameters if needed.
74+
Utils.openUrl(link);
75+
}
76+
}
77+
78+
79+
```
80+
81+
### Vue
82+
83+
```typescript
84+
import Vue from 'nativescript-vue';
85+
86+
Vue.registerElement('HTMLLabel', () => require('@nativescript-community/ui-label').Label);
87+
```
88+
89+
```html
90+
<!-- Normal Label Usage -->
91+
<HTMLLabel
92+
fontSize="50"
93+
fontFamily="Cabin Sketch,res/cabinsketch"
94+
width="100%"
95+
paddingTop="5"
96+
color="#336699"
97+
textWrap="true"
98+
:html="someBindedValue"
99+
verticalAlignment="top"
100+
/>
101+
102+
<!-- Clickable Link Usage -->
103+
<HTMLLabel
104+
html="<a href='https://youtube.com'>Open Youtube.com</a>"
105+
linkColor="pink"
106+
linkUnderline="false"
107+
@linkTap="onLinkTap($event)"
108+
fontFamily="OpenSans"
109+
fontSize="16"
110+
margin="2 5 5 5"
111+
textWrap="true"
112+
></HTMLLabel>
113+
```
114+
115+
```typescript
116+
<script lang="ts">
117+
import Vue from 'vue';
118+
119+
export default Vue.extend({
120+
data() {
121+
return {
122+
someBindedValue: "<p>This is really powerful. <b>Amazing to be quite honest</b></p>",
123+
};
124+
},
125+
methods: {
126+
// event binded to the linkTap on the HTMLLabel
127+
onLinkTap(args) {
128+
Utils.openUrl(args.link);
129+
},
130+
},
131+
beforeDestroy() {},
132+
});
133+
</script>
134+
```
135+
32136
### Properties
33-
* **html**
34-
Html text that will be used to render text. HTML supported tags are a bit different on iOS and Android. To make sure it works as expected, for now only used Android [supported ones](https://stackoverflow.com/questions/9754076/which-html-tags-are-supported-by-android-textview)
35137

36-
* **verticalTextAlignment**
37-
You can also set it through css with `vertical-text-alignment`
138+
- **html**
139+
Html text that will be used to render text. HTML supported tags are a bit different on iOS and Android. To make sure it works as expected, for now only used Android [supported ones](https://stackoverflow.com/questions/9754076/which-html-tags-are-supported-by-android-textview).
140+
141+
If using a `url` with parameters, be sure to encode the query string so Android can open the link accordingly.
142+
143+
- **verticalTextAlignment**
144+
You can also set it through css with `vertical-text-alignment`
145+
146+
- **textShadow**
147+
You can also set it through css with `text-shadow`. The format is `offsetx offsety blurradius color`
148+
149+
- **linkColor**
150+
Color for any `<a>` tags inside the `HTMLLabel`.
38151

39-
* **textShadow**
40-
You can also set it through css with `text-shadow`. The format is `offsetx offsety blurradius color`
152+
- **linkUnderline**
153+
Boolean to enable underline for any `<a>` tags inside the `HTMLLabel`.
154+
- **linkTap**
155+
Event to handle taps of any `<a>` tags inside the `HTMLLabel`. Access the `link` property of the event data from the `linkTap` event. See Samples above for example.
41156

42157
## Improvements
43158

44-
* Override the {N} font loading system to make it much faster
45-
* faster creation of `FormattedString`
46-
* faster label creation and drawing, especially on android
159+
- Override the {N} font loading system to make it much faster
160+
- faster creation of `FormattedString`
161+
- faster label creation and drawing, especially on android

0 commit comments

Comments
 (0)