diff --git a/packages/core/ui/html-view/html-view-common.ts b/packages/core/ui/html-view/html-view-common.ts index 8b95e922f..032c669a6 100644 --- a/packages/core/ui/html-view/html-view-common.ts +++ b/packages/core/ui/html-view/html-view-common.ts @@ -1,5 +1,6 @@ import { CssProperty } from '../core/properties'; import { View, CSSType } from '../core/view'; +import { booleanConverter } from '../core/view-base'; import { Property } from '../core/properties'; import { Style } from '../styling/style'; import { Color } from '../../color'; @@ -8,6 +9,7 @@ import { HtmlView as HtmlViewDefinition } from '.'; @CSSType('HtmlView') export class HtmlViewBase extends View implements HtmlViewDefinition { public html: string; + public selectable: boolean; } HtmlViewBase.prototype.recycleNativeView = 'auto'; @@ -20,6 +22,13 @@ export const htmlProperty = new Property({ }); htmlProperty.register(HtmlViewBase); +export const selectableProperty = new Property({ + name: 'selectable', + defaultValue: true, + valueConverter: booleanConverter, +}); +selectableProperty.register(HtmlViewBase); + export const linkColorProperty = new CssProperty({ name: 'linkColor', cssName: 'link-color', diff --git a/packages/core/ui/html-view/index.android.ts b/packages/core/ui/html-view/index.android.ts index f9d56ffbd..7a3b273cd 100644 --- a/packages/core/ui/html-view/index.android.ts +++ b/packages/core/ui/html-view/index.android.ts @@ -1,7 +1,7 @@ import { Color } from '../../color'; import { Font } from '../styling/font'; import { colorProperty, fontSizeProperty, fontInternalProperty } from '../styling/style-properties'; -import { HtmlViewBase, htmlProperty, linkColorProperty } from './html-view-common'; +import { HtmlViewBase, htmlProperty, selectableProperty, linkColorProperty } from './html-view-common'; export * from './html-view-common'; @@ -41,7 +41,19 @@ export class HtmlView extends HtmlViewBase { mask = 0; } this.nativeViewProtected.setAutoLinkMask(mask); - this.nativeViewProtected.setText(android.text.Html.fromHtml(value)); + const apiLevel = android.os.Build.VERSION.SDK_INT; + if (apiLevel >= 24) { + this.nativeViewProtected.setText(android.text.Html.fromHtml(value, android.text.Html.FROM_HTML_MODE_LEGACY)); + } else { + this.nativeViewProtected.setText(android.text.Html.fromHtml(value)); + } + } + + [selectableProperty.getDefault](): boolean { + return true; + } + [selectableProperty.setNative](value: boolean) { + this.nativeViewProtected.setTextIsSelectable(value); } [colorProperty.getDefault](): android.content.res.ColorStateList { @@ -59,7 +71,6 @@ export class HtmlView extends HtmlViewBase { return this.nativeViewProtected.getLinkTextColors(); } [linkColorProperty.setNative](value: Color | android.content.res.ColorStateList) { - const color = value instanceof Color ? value.android : value; if (value instanceof Color) { this.nativeViewProtected.setLinkTextColor(value.android); } else { diff --git a/packages/core/ui/html-view/index.d.ts b/packages/core/ui/html-view/index.d.ts index 9d256c53b..dcc408b44 100644 --- a/packages/core/ui/html-view/index.d.ts +++ b/packages/core/ui/html-view/index.d.ts @@ -17,10 +17,11 @@ export class HtmlView extends View { */ ios: any /* UITextView */; - /** - * Gets or sets html string for the HtmlView. - */ + /** Gets or sets html string for the HtmlView. */ html: string; + + /** Gets or sets a value indicating whether HtmlView is selectable. */ + selectable: boolean; } export const htmlProperty: Property; diff --git a/packages/core/ui/html-view/index.ios.ts b/packages/core/ui/html-view/index.ios.ts index 60be5b9ba..177b0f3b0 100644 --- a/packages/core/ui/html-view/index.ios.ts +++ b/packages/core/ui/html-view/index.ios.ts @@ -1,7 +1,7 @@ import { Color } from '../../color'; import { Font } from '../styling/font'; import { colorProperty, fontInternalProperty } from '../styling/style-properties'; -import { HtmlViewBase, htmlProperty, linkColorProperty } from './html-view-common'; +import { HtmlViewBase, htmlProperty, selectableProperty, linkColorProperty } from './html-view-common'; import { View } from '../core/view'; import { iOSNativeHelper, layout } from '../../utils'; @@ -59,10 +59,6 @@ export class HtmlView extends HtmlViewBase { } } - [htmlProperty.getDefault](): string { - return ''; - } - private renderWithStyles() { let html = this.currentHtml; const styles = []; @@ -86,11 +82,21 @@ export class HtmlView extends HtmlViewBase { } } + [htmlProperty.getDefault](): string { + return ''; + } [htmlProperty.setNative](value: string) { this.currentHtml = value; this.renderWithStyles(); } + [selectableProperty.getDefault](): boolean { + return true; + } + [selectableProperty.setNative](value: boolean) { + this.nativeViewProtected.selectable = value; + } + [colorProperty.getDefault](): UIColor { return this.nativeViewProtected.textColor; }