mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00

recycleNativeView filed now accepts: "always" | "never" | "auto". Always will recycle the nativeView no matter if its nativeView or android proprties are accessed. Never will disable recycling. Auto will recycle it only if nativeView and android properties are not accessed.
57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import {
|
|
HtmlViewBase, View, layout, htmlProperty
|
|
} from "./html-view-common";
|
|
|
|
export * from "./html-view-common";
|
|
|
|
export class HtmlView extends HtmlViewBase {
|
|
nativeViewProtected: UITextView;
|
|
|
|
constructor() {
|
|
super();
|
|
const nativeView = UITextView.new()
|
|
nativeView.scrollEnabled = false;
|
|
nativeView.editable = false;
|
|
nativeView.selectable = true;
|
|
nativeView.userInteractionEnabled = true;
|
|
nativeView.dataDetectorTypes = UIDataDetectorTypes.All;
|
|
|
|
this.nativeViewProtected = nativeView;
|
|
}
|
|
|
|
get ios(): UITextView {
|
|
return this.nativeViewProtected;
|
|
}
|
|
|
|
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
|
const nativeView = this.nativeViewProtected;
|
|
if (nativeView) {
|
|
const width = layout.getMeasureSpecSize(widthMeasureSpec);
|
|
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
|
|
|
|
const height = layout.getMeasureSpecSize(heightMeasureSpec);
|
|
const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
|
|
|
|
const desiredSize = layout.measureNativeView(nativeView, width, widthMode, height, heightMode);
|
|
|
|
const labelWidth = widthMode === layout.AT_MOST ? Math.min(desiredSize.width, width) : desiredSize.width;
|
|
const measureWidth = Math.max(labelWidth, this.effectiveMinWidth);
|
|
const measureHeight = Math.max(desiredSize.height, this.effectiveMinHeight);
|
|
|
|
const widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
|
|
const heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
|
|
|
this.setMeasuredDimension(widthAndState, heightAndState);
|
|
}
|
|
}
|
|
|
|
[htmlProperty.getDefault](): string {
|
|
return "";
|
|
}
|
|
[htmlProperty.setNative](value: string) {
|
|
const htmlString = NSString.stringWithString(value + "");
|
|
const nsData = htmlString.dataUsingEncoding(NSUnicodeStringEncoding);
|
|
this.nativeViewProtected.attributedText = NSAttributedString.alloc().initWithDataOptionsDocumentAttributesError(nsData, <any>{ [NSDocumentTypeDocumentAttribute]: NSHTMLTextDocumentType }, null);
|
|
}
|
|
}
|