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

* Layout round instead of cailing Add helper method to layout module to convert to/from dips to px and measure the native view whiteSpace affects layout added for iOS Fix bug in switch onMeasure implementation Fix bug in cssValueToDevicePixels iOS implementation ActionBar for iOS is measured with AT_MOST modifier * Fix switch measure routine
61 lines
2.1 KiB
TypeScript
61 lines
2.1 KiB
TypeScript
import {
|
|
HtmlViewBase, View, layout, htmlProperty
|
|
} from "./html-view-common";
|
|
|
|
export * from "./html-view-common";
|
|
|
|
export class HtmlView extends HtmlViewBase {
|
|
private _ios: UITextView;
|
|
|
|
constructor() {
|
|
super();
|
|
this._ios = UITextView.new();
|
|
|
|
this._ios.scrollEnabled = false;
|
|
this._ios.editable = false;
|
|
this._ios.selectable = true;
|
|
this._ios.userInteractionEnabled = true;
|
|
this._ios.dataDetectorTypes = UIDataDetectorTypes.All;
|
|
}
|
|
|
|
get ios(): UITextView {
|
|
return this._ios;
|
|
}
|
|
|
|
get _nativeView(): UITextView {
|
|
return this._ios;
|
|
}
|
|
|
|
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
|
var nativeView = this._nativeView;
|
|
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 = Math.min(desiredSize.width, 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);
|
|
}
|
|
}
|
|
|
|
get [htmlProperty.native](): string {
|
|
return "";
|
|
}
|
|
set [htmlProperty.native](value: string) {
|
|
const htmlString = NSString.stringWithString(value + "");
|
|
const nsData = htmlString.dataUsingEncoding(NSUnicodeStringEncoding);
|
|
this._ios.attributedText = NSAttributedString.alloc().initWithDataOptionsDocumentAttributesError(nsData, <any>{ [NSDocumentTypeDocumentAttribute]: NSHTMLTextDocumentType }, null);
|
|
}
|
|
}
|