HtmlView UI component added + test

This commit is contained in:
Vladimir Enchev
2015-07-15 11:59:00 +03:00
parent 57312ef1f3
commit 835ab8c142
8 changed files with 73 additions and 9 deletions

View File

@@ -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",

View File

@@ -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("");
}
}

View File

@@ -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 {

View File

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