feat(HtmlView): selectable property (#10057)

This commit is contained in:
Ruslan Lekhman
2022-10-14 19:47:59 -06:00
committed by GitHub
parent 4a0e1c9aa1
commit ca9c0928d0
4 changed files with 38 additions and 11 deletions

View File

@ -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<HtmlViewBase, string>({
});
htmlProperty.register(HtmlViewBase);
export const selectableProperty = new Property<HtmlViewBase, boolean>({
name: 'selectable',
defaultValue: true,
valueConverter: booleanConverter,
});
selectableProperty.register(HtmlViewBase);
export const linkColorProperty = new CssProperty<Style, Color>({
name: 'linkColor',
cssName: 'link-color',

View File

@ -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(<any>android.text.Html.fromHtml(value));
const apiLevel = android.os.Build.VERSION.SDK_INT;
if (apiLevel >= 24) {
this.nativeViewProtected.setText(<any>android.text.Html.fromHtml(value, android.text.Html.FROM_HTML_MODE_LEGACY));
} else {
this.nativeViewProtected.setText(<any>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 {

View File

@ -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<HtmlView, string>;

View File

@ -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;
}