mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 01:43:14 +08:00
feat(HtmlView): selectable property (#10057)
This commit is contained in:
@ -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',
|
||||
|
@ -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 {
|
||||
|
7
packages/core/ui/html-view/index.d.ts
vendored
7
packages/core/ui/html-view/index.d.ts
vendored
@ -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>;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user