mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
HtmlView UI component added + test
This commit is contained in:
@@ -31,6 +31,7 @@ var MODULES = {
|
||||
"FormattedString": "text/formatted-string",
|
||||
"Span": "text/span",
|
||||
"WebView": "ui/web-view",
|
||||
"HtmlView": "ui/html-view",
|
||||
"SegmentedBar": "ui/segmented-bar",
|
||||
"SegmentedBarItem": "ui/segmented-bar",
|
||||
"ToolBar": "ui/tool-bar",
|
||||
|
||||
@@ -11,6 +11,8 @@ function onHtmlPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
|
||||
if (types.isString(data.newValue)) {
|
||||
view.android.setText(<any>android.text.Html.fromHtml(data.newValue));
|
||||
} else {
|
||||
view.android.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
4
ui/html-view/html-view.d.ts
vendored
4
ui/html-view/html-view.d.ts
vendored
@@ -6,7 +6,9 @@ declare module "ui/html-view" {
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
|
||||
/**
|
||||
* Represents a view with html content.
|
||||
* Represents a view with html content. Use this component instead WebView when want to show just static HTML content.
|
||||
* [iOS support](https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSAttributedString_UIKit_Additions/#//apple_ref/occ/instm/NSAttributedString/initWithData:options:documentAttributes:error:)
|
||||
* [android support](http://developer.android.com/reference/android/text/Html.html)
|
||||
*/
|
||||
export class HtmlView extends view.View {
|
||||
|
||||
|
||||
@@ -8,16 +8,16 @@ import viewModule = require("ui/core/view");
|
||||
|
||||
function onHtmlPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var view = <HtmlView>data.object;
|
||||
if (!view.android) {
|
||||
if (!view.ios) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (types.isString(data.newValue)) {
|
||||
var htmlString = NSString.stringWithString(data.newValue);
|
||||
var nsData = htmlString.dataUsingEncoding(NSUnicodeStringEncoding);
|
||||
var options = NSDictionary.new();
|
||||
options.setValueForKey(NSDocumentTypeDocumentAttribute, NSHTMLTextDocumentType);
|
||||
view.ios.attributedText = NSAttributedString.alloc().initWithDataOptionsDocumentAttributesError(nsData, options, null);
|
||||
view.ios.attributedText = NSAttributedString.alloc().initWithDataOptionsDocumentAttributesError(nsData, <any>{ [NSDocumentTypeDocumentAttribute]: NSHTMLTextDocumentType }, null);
|
||||
} else {
|
||||
view.ios.attributedText = NSAttributedString.new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,9 +66,8 @@ export class HtmlView extends common.HtmlView {
|
||||
|
||||
var nativeSize = nativeView.sizeThatFits(CGSizeMake(width, height));
|
||||
var labelWidth = nativeSize.width;
|
||||
//if (!this.textWrap) {
|
||||
labelWidth = Math.min(labelWidth, width);
|
||||
//}
|
||||
|
||||
labelWidth = Math.min(labelWidth, width);
|
||||
|
||||
var measureWidth = Math.max(labelWidth, this.minWidth);
|
||||
var measureHeight = Math.max(nativeSize.height, this.minHeight);
|
||||
|
||||
Reference in New Issue
Block a user