UNPKG

3.44 kBJavaScriptView Raw
1import { Color } from '../../color';
2import { SDK_VERSION } from '../../utils/constants';
3import { Font } from '../styling/font';
4import { colorProperty, fontSizeProperty, fontInternalProperty } from '../styling/style-properties';
5import { HtmlViewBase, htmlProperty, selectableProperty, linkColorProperty } from './html-view-common';
6export * from './html-view-common';
7export class HtmlView extends HtmlViewBase {
8 createNativeView() {
9 return new android.widget.TextView(this._context);
10 }
11 initNativeView() {
12 super.initNativeView();
13 const nativeView = this.nativeViewProtected;
14 // Allow text selection
15 nativeView.setTextIsSelectable(true);
16 // This makes the html <a href...> work
17 nativeView.setLinksClickable(true);
18 nativeView.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
19 }
20 resetNativeView() {
21 super.resetNativeView();
22 this.nativeViewProtected.setAutoLinkMask(0);
23 }
24 [htmlProperty.getDefault]() {
25 return '';
26 }
27 [htmlProperty.setNative](value) {
28 // If the data.newValue actually has a <a...> in it; we need to disable autolink mask
29 // it internally disables the coloring, but then the <a> links won't work.. So to support both
30 // styles of links (html and just text based) we have to manually enable/disable the autolink mask
31 let mask = 15;
32 if (value.search(/<a\s/i) >= 0) {
33 mask = 0;
34 }
35 this.nativeViewProtected.setAutoLinkMask(mask);
36 if (SDK_VERSION >= 24) {
37 this.nativeViewProtected.setText(android.text.Html.fromHtml(value, android.text.Html.FROM_HTML_MODE_LEGACY));
38 }
39 else {
40 this.nativeViewProtected.setText(android.text.Html.fromHtml(value));
41 }
42 }
43 [selectableProperty.getDefault]() {
44 return true;
45 }
46 [selectableProperty.setNative](value) {
47 this.nativeViewProtected.setTextIsSelectable(value);
48 }
49 [colorProperty.getDefault]() {
50 return this.nativeViewProtected.getTextColors();
51 }
52 [colorProperty.setNative](value) {
53 if (value instanceof Color) {
54 this.nativeViewProtected.setTextColor(value.android);
55 }
56 else {
57 this.nativeViewProtected.setTextColor(value);
58 }
59 }
60 [linkColorProperty.getDefault]() {
61 return this.nativeViewProtected.getLinkTextColors();
62 }
63 [linkColorProperty.setNative](value) {
64 if (value instanceof Color) {
65 this.nativeViewProtected.setLinkTextColor(value.android);
66 }
67 else {
68 this.nativeViewProtected.setLinkTextColor(value);
69 }
70 }
71 [fontInternalProperty.getDefault]() {
72 return this.nativeViewProtected.getTypeface();
73 }
74 [fontInternalProperty.setNative](value) {
75 const font = value instanceof Font ? value.getAndroidTypeface() : value;
76 this.nativeViewProtected.setTypeface(font);
77 }
78 [fontSizeProperty.getDefault]() {
79 return { nativeSize: this.nativeViewProtected.getTextSize() };
80 }
81 [fontSizeProperty.setNative](value) {
82 if (typeof value === 'number') {
83 this.nativeViewProtected.setTextSize(value);
84 }
85 else {
86 this.nativeViewProtected.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.nativeSize);
87 }
88 }
89}
90//# sourceMappingURL=index.android.js.map
\No newline at end of file