Enable Button tests, fix AbsoluteLayout tests

This commit is contained in:
Panayot Cankov
2017-01-20 17:51:49 +02:00
parent e34b0f622c
commit 312a99667e
14 changed files with 139 additions and 162 deletions

View File

@ -4,9 +4,8 @@ import * as viewModule from "ui/core/view";
import * as pagesModule from "ui/page"; import * as pagesModule from "ui/page";
import * as buttonTestsNative from "./button-tests-native"; import * as buttonTestsNative from "./button-tests-native";
import * as colorModule from "color"; import * as colorModule from "color";
// import * as enums from "ui/enums"; import * as formattedStringModule from "text/formatted-string";
// import * as formattedStringModule from "text/formatted-string"; import * as spanModule from "text/span";
// import * as spanModule from "text/span";
// >> button-require // >> button-require
import * as buttonModule from "ui/button"; import * as buttonModule from "ui/button";
@ -310,62 +309,61 @@ export var testNativeTextAlignmentFromLocal = function () {
}); });
} }
// TODO: Enable these when. export var test_WhenFormattedTextPropertyChanges_TextIsUpdated_Button = function () {
// export var test_WhenFormattedTextPropertyChanges_TextIsUpdated_Button = function () { var firstSpan = new spanModule.Span();
// var firstSpan = new spanModule.Span(); firstSpan.fontSize = 10;
// firstSpan.fontSize = 10; firstSpan.text = "First";
// firstSpan.text = "First"; var secondSpan = new spanModule.Span();
// var secondSpan = new spanModule.Span(); secondSpan.fontSize = 15;
// secondSpan.fontSize = 15; secondSpan.text = "Second";
// secondSpan.text = "Second"; var thirdSpan = new spanModule.Span();
// var thirdSpan = new spanModule.Span(); thirdSpan.fontSize = 20;
// thirdSpan.fontSize = 20; thirdSpan.text = "Third";
// thirdSpan.text = "Third"; var formattedString1 = new formattedStringModule.FormattedString();
// var formattedString1 = new formattedStringModule.FormattedString(); formattedString1.spans.push(firstSpan);
// formattedString1.spans.push(firstSpan); var formattedString2 = new formattedStringModule.FormattedString();
// var formattedString2 = new formattedStringModule.FormattedString(); formattedString2.spans.push(secondSpan);
// formattedString2.spans.push(secondSpan); formattedString2.spans.push(thirdSpan);
// formattedString2.spans.push(thirdSpan);
// var view = new buttonModule.Button(); var view = new buttonModule.Button();
// helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) { helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
// TKUnit.assertEqual(view.text, ""); TKUnit.assertEqual(view.text, "");
// view.formattedText = formattedString1; view.formattedText = formattedString1;
// TKUnit.assertEqual(view.text, "First"); TKUnit.assertEqual(view.text, "First");
// view.formattedText = formattedString2; view.formattedText = formattedString2;
// TKUnit.assertEqual(view.text, "SecondThird"); TKUnit.assertEqual(view.text, "SecondThird");
// formattedString2.spans.getItem(0).text = "Mecond"; formattedString2.spans.getItem(0).text = "Mecond";
// TKUnit.assertEqual(view.text, "MecondThird"); TKUnit.assertEqual(view.text, "MecondThird");
// view.formattedText = null; view.formattedText = null;
// TKUnit.assertEqual(view.text, ""); TKUnit.assertEqual(view.text, "");
// }); });
// } }
// export function test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormattedText_DoesNotCrash() { export function test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormattedText_DoesNotCrash() {
// let view = new buttonModule.Button(); let view = new buttonModule.Button();
// helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) { helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
// view.text = "NormalText"; view.text = "NormalText";
// view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;"); view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
// TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.uppercase, "TextTransform"); TKUnit.assertEqual(view.style.textTransform, "uppercase", "TextTransform");
// TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.underline, "TextDecoration"); TKUnit.assertEqual(view.style.textDecoration, "underline", "TextDecoration");
// TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing"); TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
// }); });
// } }
// export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedText_DoesNotCrash() { export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedText_DoesNotCrash() {
// let view = new buttonModule.Button(); let view = new buttonModule.Button();
// let formattedString = helper._generateFormattedString(); let formattedString = helper._generateFormattedString();
// helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) { helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
// view.formattedText = formattedString; view.formattedText = formattedString;
// view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;"); view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");
// TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.uppercase, "TextTransform"); TKUnit.assertEqual(view.style.textTransform, "uppercase", "TextTransform");
// TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.underline, "TextDecoration"); TKUnit.assertEqual(view.style.textDecoration, "underline", "TextDecoration");
// TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing"); TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
// }); });
// } }

View File

@ -377,32 +377,6 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
TKUnit.assertEqual(label.text, secondExpValue); TKUnit.assertEqual(label.text, secondExpValue);
} }
// TODO: Check if bindings will be cleared when the target property is set.
// public test_BindingToText_BindingContext_SetingLocalValue() {
// const label = this.testView;
// this.waitUntilTestElementIsLoaded();
// const firstExpValue = "Expected Value";
// const bindingOptions: bindable.BindingOptions = {
// sourceProperty: "sourceProperty",
// targetProperty: "text"
// };
// label.bind(bindingOptions);
// const firstSourceObject = new observableModule.Observable();
// firstSourceObject.set("sourceProperty", firstExpValue);
// this.testPage.bindingContext = firstSourceObject;
// TKUnit.assertEqual(label.text, firstExpValue);
// const secondExpValue = "Second value";
// label.text = secondExpValue;
// TKUnit.assertEqual(label.text, secondExpValue);
// firstSourceObject.set("sourceProperty", "some value");
// // after setting a value one way binding should be gone.
// TKUnit.assertEqual(label.text, secondExpValue);
// }
private expectedTextAlignment: "right" = "right"; private expectedTextAlignment: "right" = "right";
public testLocalTextAlignmentFromCss() { public testLocalTextAlignmentFromCss() {
const label = this.testView; const label = this.testView;

View File

@ -82,27 +82,26 @@ export class AbsoluteLayoutTest extends testModule.UITest<absoluteLayoutModule.A
layoutHelper.assertLayout(btn, 25, 35, 100, 100); layoutHelper.assertLayout(btn, 25, 35, 100, 100);
} }
// TODO: This mostly works, but the current logic will check the button to have width and margin and will make it CENTER clearing the effect of the 20 pixels margin public test_percent_children_support() {
// public test_percent_children_support() { let layout = this.testView;
// let layout = this.testView; layout.width = { value: 200, unit: "px" };
// layout.width = { value: 200, unit: "px" }; layout.height = { value: 200, unit: "px" };
// layout.height = { value: 200, unit: "px" };
// let btn = new layoutHelper.MyButton(); let btn = new layoutHelper.MyButton();
// (<any>btn).width = "50%"; (<any>btn).width = "50%";
// (<any>btn).height = "50%"; (<any>btn).height = "50%";
// btn.margin = "10%"; btn.margin = "10%";
// layout.addChild(btn); layout.addChild(btn);
// this.waitUntilTestElementLayoutIsValid(); this.waitUntilTestElementLayoutIsValid();
// // AbsoluteLayout measures with 0/UNSPECIFIED so we cannot support percents in it. // AbsoluteLayout measures with 0/UNSPECIFIED so we cannot support percents in it.
// layoutHelper.assertMeasure(btn, 100, 100); layoutHelper.assertMeasure(btn, 100, 100);
// layoutHelper.assertLayout(btn, 20, 20, btn.getMeasuredWidth(), btn.getMeasuredHeight()); layoutHelper.assertLayout(btn, 20, 20, btn.getMeasuredWidth(), btn.getMeasuredHeight());
// TKUnit.assertEqual(btn.getMeasuredWidth(), 100, "Button MeasuredWidth incorrect"); TKUnit.assertEqual(btn.getMeasuredWidth(), 100, "Button MeasuredWidth incorrect");
// TKUnit.assertEqual(btn.getMeasuredHeight(), 100, "Button MeasuredHeight incorrect"); TKUnit.assertEqual(btn.getMeasuredHeight(), 100, "Button MeasuredHeight incorrect");
// } }
public test_percent_support_nativeLayoutParams_are_correct() { public test_percent_support_nativeLayoutParams_are_correct() {
commonTests.percent_support_nativeLayoutParams_are_correct(this); commonTests.percent_support_nativeLayoutParams_are_correct(this);

View File

@ -159,30 +159,21 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout>
}, "setColumnSpan called with null should throw exception"); }, "setColumnSpan called with null should throw exception");
} }
// TODO: These 4 asserted that wrong numbers will throw and now they are clamped internally to valid values and does not throw. public test_setRow_shouldNotThrow_onNegativeValues() {
// public test_setRow_shouldThrow_onNegativeValues() { GridLayout.setRow(new Button(), -1);
// TKUnit.assertThrows(() => { }
// GridLayout.setRow(new Button(), -1);
// }, "setRow should throw when value < 0");
// }
// public test_setRowSpan_shouldThrow_onNotPositiveValues() { public test_setRowSpan_shouldNotThrow_onNotPositiveValues() {
// TKUnit.assertThrows(() => { GridLayout.setRowSpan(new Button(), 0);
// GridLayout.setRowSpan(new Button(), 0); }
// }, "setRowSpan should throw when value <= 0");
// }
// public test_setColumn_shouldThrow_onNegativeValues() { public test_setColumn_shouldNotThrow_onNegativeValues() {
// TKUnit.assertThrows(() => { GridLayout.setColumn(new Button(), -1);
// GridLayout.setColumn(new Button(), -1); }
// }, "setColumn should when value < 0");
// }
// public test_setColumnSpan_shouldThrow_onNotPositiveValues() { public test_setColumnSpan_shouldNotThrow_onNotPositiveValues() {
// TKUnit.assertThrows(() => { GridLayout.setColumnSpan(new Button(), 0);
// GridLayout.setColumnSpan(new Button(), 0); }
// }, "setColumnSpan should throw when value <= 0");
// }
public test_addRow_shouldThrow_onNullValues() { public test_addRow_shouldThrow_onNullValues() {
TKUnit.assertThrows(() => { TKUnit.assertThrows(() => {
@ -325,12 +316,11 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout>
} }
} }
// TODO: This used to throw but the underlaying "makeParser" used fallbacks to default value instead of throwing public test_ItemSpec_constructor_throws_onWrongType() {
// public test_ItemSpec_constructor_throws_onWrongType() { TKUnit.assertThrows(() => {
// TKUnit.assertThrows(() => { return new ItemSpec(1, <any>"unsupported");
// return new ItemSpec(1, <any>"unsupported"); }, "Invalid value: unsupported");
// }, "'ItemSpec type' incorrect value."); }
// }
public test_ItemSpec_auto() { public test_ItemSpec_auto() {
var w = new ItemSpec(1, "auto"); var w = new ItemSpec(1, "auto");

View File

@ -946,9 +946,13 @@ export function makeValidator<T>(...values: T[]): (value: any) => value is T {
return (value: any): value is T => set.has(value); return (value: any): value is T => set.has(value);
} }
export function makeParser<T>(isValid: (value: any) => boolean, def: T): (value: any) => T { export function makeParser<T>(isValid: (value: any) => boolean): (value: any) => T {
return value => { return value => {
const lower = value && value.toLowerCase(); const lower = value && value.toLowerCase();
return isValid(lower) ? lower : def; if (isValid(lower)) {
return lower;
} else {
throw new Error("Invalid value: " + value);
}
} }
} }

View File

@ -1237,7 +1237,7 @@ export namespace HorizontalAlignment {
export const RIGHT: "right" = "right"; export const RIGHT: "right" = "right";
export const STRETCH: "stretch" = "stretch"; export const STRETCH: "stretch" = "stretch";
export const isValid = makeValidator<HorizontalAlignment>(LEFT, CENTER, RIGHT, STRETCH); export const isValid = makeValidator<HorizontalAlignment>(LEFT, CENTER, RIGHT, STRETCH);
export const parse = makeParser(isValid, STRETCH); export const parse = makeParser<HorizontalAlignment>(isValid);
} }
export const horizontalAlignmentProperty = new CssProperty<Style, HorizontalAlignment>({ name: "horizontalAlignment", cssName: "horizontal-align", defaultValue: HorizontalAlignment.STRETCH, affectsLayout: isIOS, valueConverter: HorizontalAlignment.parse }); export const horizontalAlignmentProperty = new CssProperty<Style, HorizontalAlignment>({ name: "horizontalAlignment", cssName: "horizontal-align", defaultValue: HorizontalAlignment.STRETCH, affectsLayout: isIOS, valueConverter: HorizontalAlignment.parse });
@ -1250,7 +1250,16 @@ export namespace VerticalAlignment {
export const BOTTOM: "bottom" = "bottom"; export const BOTTOM: "bottom" = "bottom";
export const STRETCH: "stretch" = "stretch"; export const STRETCH: "stretch" = "stretch";
export const isValid = makeValidator<VerticalAlignment>(TOP, MIDDLE, BOTTOM, STRETCH); export const isValid = makeValidator<VerticalAlignment>(TOP, MIDDLE, BOTTOM, STRETCH);
export const parse = makeParser(isValid, STRETCH); export const parse = value => {
const lower = value && value.toLowerCase();
if (lower === "canter") {
return MIDDLE;
} else if (isValid(lower)) {
return lower;
} else {
throw new Error("Invalid value: " + value);
}
}
} }
export const verticalAlignmentProperty = new CssProperty<Style, VerticalAlignment>({ name: "verticalAlignment", cssName: "vertical-align", defaultValue: VerticalAlignment.STRETCH, affectsLayout: isIOS, valueConverter: VerticalAlignment.parse }); export const verticalAlignmentProperty = new CssProperty<Style, VerticalAlignment>({ name: "verticalAlignment", cssName: "vertical-align", defaultValue: VerticalAlignment.STRETCH, affectsLayout: isIOS, valueConverter: VerticalAlignment.parse });
@ -1559,7 +1568,7 @@ export namespace BackgroundRepeat {
export const REPEAT_Y: "repeat-y" = "repeat-y"; export const REPEAT_Y: "repeat-y" = "repeat-y";
export const NO_REPEAT: "no-repeat" = "no-repeat"; export const NO_REPEAT: "no-repeat" = "no-repeat";
export const isValid = makeValidator<BackgroundRepeat>(REPEAT, REPEAT_X, REPEAT_Y, NO_REPEAT); export const isValid = makeValidator<BackgroundRepeat>(REPEAT, REPEAT_X, REPEAT_Y, NO_REPEAT);
export const parse = makeParser(isValid, undefined); export const parse = makeParser<BackgroundRepeat>(isValid);
} }
export const backgroundRepeatProperty = new CssProperty<Style, BackgroundRepeat>({ export const backgroundRepeatProperty = new CssProperty<Style, BackgroundRepeat>({
@ -2016,7 +2025,7 @@ export namespace Visibility {
export const HIDDEN: "hidden" = "hidden"; export const HIDDEN: "hidden" = "hidden";
export const COLLAPSE: "collapse" = "collapse"; export const COLLAPSE: "collapse" = "collapse";
export const isValid = makeValidator<Visibility>(VISIBLE, HIDDEN, COLLAPSE); export const isValid = makeValidator<Visibility>(VISIBLE, HIDDEN, COLLAPSE);
export const parse = makeParser(isValid, VISIBLE); export const parse = makeParser<Visibility>(isValid);
} }
export const visibilityProperty = new CssProperty<Style, Visibility>({ export const visibilityProperty = new CssProperty<Style, Visibility>({

View File

@ -270,5 +270,5 @@ declare module "ui/core/properties" {
export function resetCSSProperties(style: Style): void; export function resetCSSProperties(style: Style): void;
export function makeValidator<T>(...values: T[]): (value: any) => value is T; export function makeValidator<T>(...values: T[]): (value: any) => value is T;
export function makeParser<T>(isValid: (value: any) => boolean, def: T): (value: any) => T; export function makeParser<T>(isValid: (value: any) => boolean): (value: any) => T;
} }

View File

@ -54,8 +54,8 @@ export class AbsoluteLayout extends AbsoluteLayoutBase {
const childLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + child.effectiveLeft; const childLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + child.effectiveLeft;
const childTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + child.effectiveTop; const childTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + child.effectiveTop;
const childRight = childLeft + childWidth + this.effectiveMarginLeft + this.effectiveMarginRight; const childRight = childLeft + childWidth + child.effectiveMarginLeft + child.effectiveMarginRight;
const childBottom = childTop + childHeight + this.effectiveMarginTop + this.effectiveMarginBottom; const childBottom = childTop + childHeight + child.effectiveMarginTop + child.effectiveMarginBottom;
View.layoutChild(this, child, childLeft, childTop, childRight, childBottom); View.layoutChild(this, child, childLeft, childTop, childRight, childBottom);
}); });

View File

@ -35,7 +35,7 @@ export namespace FlexDirection {
export const COLUMN_REVERSE: "column-reverse" = "column-reverse"; export const COLUMN_REVERSE: "column-reverse" = "column-reverse";
export const isValid = makeValidator<FlexDirection>(ROW, ROW_REVERSE, COLUMN, COLUMN_REVERSE); export const isValid = makeValidator<FlexDirection>(ROW, ROW_REVERSE, COLUMN, COLUMN_REVERSE);
export const parse = makeParser(isValid, ROW); export const parse = makeParser<FlexDirection>(isValid);
} }
export type FlexWrap = "nowrap" | "wrap" | "wrap-reverse"; export type FlexWrap = "nowrap" | "wrap" | "wrap-reverse";
@ -45,7 +45,7 @@ export namespace FlexWrap {
export const WRAP_REVERSE: "wrap-reverse" = "wrap-reverse"; export const WRAP_REVERSE: "wrap-reverse" = "wrap-reverse";
export const isValid = makeValidator<FlexWrap>(NOWRAP, WRAP, WRAP_REVERSE); export const isValid = makeValidator<FlexWrap>(NOWRAP, WRAP, WRAP_REVERSE);
export const parse = makeParser(isValid, NOWRAP); export const parse = makeParser<FlexWrap>(isValid);
} }
export type JustifyContent = "flex-start" | "flex-end" | "center" | "space-between" | "space-around"; export type JustifyContent = "flex-start" | "flex-end" | "center" | "space-between" | "space-around";
@ -57,7 +57,7 @@ export namespace JustifyContent {
export const SPACE_AROUND: "space-around" = "space-around"; export const SPACE_AROUND: "space-around" = "space-around";
export const isValid = makeValidator<JustifyContent>(FLEX_START, FLEX_END, CENTER, SPACE_BETWEEN, SPACE_AROUND); export const isValid = makeValidator<JustifyContent>(FLEX_START, FLEX_END, CENTER, SPACE_BETWEEN, SPACE_AROUND);
export const parse = makeParser(isValid, FLEX_START); export const parse = makeParser<JustifyContent>(isValid);
} }
export type FlexBasisPercent = number; export type FlexBasisPercent = number;
@ -74,7 +74,7 @@ export namespace AlignItems {
export const STRETCH: "stretch" = "stretch"; export const STRETCH: "stretch" = "stretch";
export const isValid = makeValidator<AlignItems>(FLEX_START, FLEX_END, CENTER, BASELINE, STRETCH); export const isValid = makeValidator<AlignItems>(FLEX_START, FLEX_END, CENTER, BASELINE, STRETCH);
export const parse = makeParser(isValid, FLEX_START); export const parse = makeParser<AlignItems>(isValid);
} }
export type AlignContent = "flex-start" | "flex-end" | "center" | "space-between" | "space-around" | "stretch"; export type AlignContent = "flex-start" | "flex-end" | "center" | "space-between" | "space-around" | "stretch";
@ -87,7 +87,7 @@ export namespace AlignContent {
export const STRETCH: "stretch" = "stretch"; export const STRETCH: "stretch" = "stretch";
export const isValid = makeValidator<AlignContent>(FLEX_START, FLEX_END, CENTER, SPACE_BETWEEN, SPACE_AROUND, STRETCH); export const isValid = makeValidator<AlignContent>(FLEX_START, FLEX_END, CENTER, SPACE_BETWEEN, SPACE_AROUND, STRETCH);
export const parse = makeParser(isValid, FLEX_START); export const parse = makeParser<AlignContent>(isValid);
} }
export type Order = number; export type Order = number;
@ -143,7 +143,7 @@ export namespace AlignSelf {
export const STRETCH: "stretch" = "stretch"; export const STRETCH: "stretch" = "stretch";
export const isValid = makeValidator<AlignSelf>(AUTO, FLEX_START, FLEX_END, CENTER, BASELINE, STRETCH); export const isValid = makeValidator<AlignSelf>(AUTO, FLEX_START, FLEX_END, CENTER, BASELINE, STRETCH);
export const parse = makeParser(isValid, AUTO); export const parse = makeParser<AlignSelf>(isValid);
} }
function validateArgs(element: View): View { function validateArgs(element: View): View {

View File

@ -368,5 +368,5 @@ export namespace GridUnitType {
export const STAR: "star" = "star"; export const STAR: "star" = "star";
export const AUTO: "auto" = "auto"; export const AUTO: "auto" = "auto";
export const isValid = makeValidator<GridUnitType>(PIXEL, STAR, AUTO); export const isValid = makeValidator<GridUnitType>(PIXEL, STAR, AUTO);
export const parse = makeParser(isValid, undefined); export const parse = makeParser<GridUnitType>(isValid);
} }

View File

@ -50,7 +50,7 @@ export namespace FontStyle {
export const NORMAL: "normal" = "normal"; export const NORMAL: "normal" = "normal";
export const ITALIC: "italic" = "italic"; export const ITALIC: "italic" = "italic";
export const isValid = makeValidator<FontStyle>(NORMAL, ITALIC); export const isValid = makeValidator<FontStyle>(NORMAL, ITALIC);
export const parse = makeParser(isValid, NORMAL); export const parse = makeParser<FontStyle>(isValid);
} }
export type FontWeight = "100" | "200" | "300" | "normal" | "400" | "500" | "600" | "bold" | "700" | "800" | "900"; export type FontWeight = "100" | "200" | "300" | "normal" | "400" | "500" | "600" | "bold" | "700" | "800" | "900";
@ -65,7 +65,7 @@ export namespace FontWeight {
export const EXTRA_BOLD: "800" = "800"; export const EXTRA_BOLD: "800" = "800";
export const BLACK: "900" = "900"; export const BLACK: "900" = "900";
export const isValid = makeValidator<FontWeight>(THIN, EXTRA_LIGHT, LIGHT, NORMAL, "400", MEDIUM, SEMI_BOLD, BOLD, "700", EXTRA_BOLD, BLACK); export const isValid = makeValidator<FontWeight>(THIN, EXTRA_LIGHT, LIGHT, NORMAL, "400", MEDIUM, SEMI_BOLD, BOLD, "700", EXTRA_BOLD, BLACK);
export const parse = makeParser(isValid, NORMAL); export const parse = makeParser<FontStyle>(isValid);
} }
export function parseFontFamily(value: string): Array<string> { export function parseFontFamily(value: string): Array<string> {

View File

@ -152,7 +152,7 @@ export namespace TextAlignment {
export const CENTER: "center" = "center"; export const CENTER: "center" = "center";
export const RIGHT: "right" = "right"; export const RIGHT: "right" = "right";
export const isValid = makeValidator<TextAlignment>(LEFT, CENTER, RIGHT); export const isValid = makeValidator<TextAlignment>(LEFT, CENTER, RIGHT);
export const parse = makeParser(isValid, undefined); export const parse = makeParser<TextAlignment>(isValid);
} }
export const textAlignmentProperty = new InheritedCssProperty<Style, TextAlignment>({ export const textAlignmentProperty = new InheritedCssProperty<Style, TextAlignment>({
@ -171,7 +171,7 @@ export namespace TextDecoration {
export const UNDERLINE_LINE_THROUGH: "underline line-through" = "underline line-through"; export const UNDERLINE_LINE_THROUGH: "underline line-through" = "underline line-through";
export const isValid = makeValidator<TextDecoration>(NONE, UNDERLINE, LINE_THROUGH, UNDERLINE_LINE_THROUGH); export const isValid = makeValidator<TextDecoration>(NONE, UNDERLINE, LINE_THROUGH, UNDERLINE_LINE_THROUGH);
export const parse = makeParser(isValid, NONE); export const parse = makeParser<TextDecoration>(isValid);
} }
export const textDecorationProperty = new CssProperty<Style, TextDecoration>({ export const textDecorationProperty = new CssProperty<Style, TextDecoration>({
name: "textDecoration", name: "textDecoration",
@ -189,7 +189,7 @@ export namespace TextTransform {
export const UPPERCASE: "uppercase" = "uppercase"; export const UPPERCASE: "uppercase" = "uppercase";
export const LOWERCASE: "lowercase" = "lowercase"; export const LOWERCASE: "lowercase" = "lowercase";
export const isValid = makeValidator<TextTransform>(NONE, CAPITALIZE, UPPERCASE, LOWERCASE); export const isValid = makeValidator<TextTransform>(NONE, CAPITALIZE, UPPERCASE, LOWERCASE);
export const parse = makeParser(isValid, NONE); export const parse = makeParser<TextTransform>(isValid);
} }
export const textTransformProperty = new CssProperty<Style, TextTransform>({ export const textTransformProperty = new CssProperty<Style, TextTransform>({
name: "textTransform", name: "textTransform",
@ -205,7 +205,7 @@ export namespace WhiteSpace {
export const NORMAL: "normal" = "normal"; export const NORMAL: "normal" = "normal";
export const NO_WRAP: "nowrap" = "nowrap"; export const NO_WRAP: "nowrap" = "nowrap";
export const isValid = makeValidator<WhiteSpace>(NORMAL, NO_WRAP); export const isValid = makeValidator<WhiteSpace>(NORMAL, NO_WRAP);
export const parse = makeParser(isValid, NORMAL); export const parse = makeParser<WhiteSpace>(isValid);
} }
//NB: Default value is deferent for Android and IOS //NB: Default value is deferent for Android and IOS

View File

@ -48,7 +48,7 @@ export class TextBase extends TextBaseCommon {
} }
set [textTransformProperty.native](value: TextTransform | android.text.method.TransformationMethod) { set [textTransformProperty.native](value: TextTransform | android.text.method.TransformationMethod) {
if (typeof value === "string") { if (typeof value === "string") {
this._nativeView.setTransformationMethod(new TextTransformation(this.text, this.formattedText, value)); this._nativeView.setTransformationMethod(new TextTransformation(this));
} else { } else {
this._nativeView.setTransformationMethod(value); this._nativeView.setTransformationMethod(value);
} }
@ -207,36 +207,39 @@ export class TextBase extends TextBaseCommon {
@Interfaces([android.text.method.TransformationMethod]) @Interfaces([android.text.method.TransformationMethod])
class TextTransformation extends android.text.method.ReplacementTransformationMethod { class TextTransformation extends android.text.method.ReplacementTransformationMethod {
constructor(public originalText: string, public formattedText: FormattedString, public textTransform: TextTransform) { constructor(public textBase: TextBase) {
super(); super();
return global.__native(this); return global.__native(this);
} }
protected getOriginal(): native.Array<string> { protected getOriginal(): native.Array<string> {
return convertStringToNativeCharArray(this.formattedText ? this.formattedText.toString() : this.originalText); return convertStringToNativeCharArray(this.textBase.formattedText ? this.textBase.formattedText.toString() : this.textBase.text);
} }
protected getReplacement(): native.Array<string> { protected getReplacement(): native.Array<string> {
let replacementString: string = ""; let replacementString: string = "";
if (this.formattedText) { const formattedText = this.textBase.formattedText;
for (let i = 0, length = this.formattedText.spans.length; i < length; i++) { const textTransform = this.textBase.textTransform;
let span = this.formattedText.spans.getItem(i); if (formattedText) {
replacementString += getTransformedText(span.text, this.textTransform); for (let i = 0, length = formattedText.spans.length; i < length; i++) {
let span = formattedText.spans.getItem(i);
replacementString += getTransformedText(span.text, textTransform);
} }
} }
else { else {
replacementString = getTransformedText(this.originalText, this.textTransform); replacementString = getTransformedText(this.textBase.text, textTransform);
} }
return convertStringToNativeCharArray(replacementString); return convertStringToNativeCharArray(replacementString);
} }
public getTransformation(charSeq: any, view: android.view.View): any { public getTransformation(charSeq: any, view: android.view.View): any {
if (this.formattedText) { const formattedText = this.textBase.formattedText;
return createSpannableStringBuilder(this.formattedText); if (formattedText) {
return createSpannableStringBuilder(formattedText);
} }
else { else {
return getTransformedText(this.originalText, this.textTransform); return getTransformedText(this.textBase.text, this.textBase.textTransform);
} }
} }
} }

View File

@ -1,14 +1,14 @@
declare module "ui/text-base" { declare module "ui/text-base" {
import { View, AddChildFromBuilder, Property, CssProperty, InheritedCssProperty, Style, Length } from "ui/core/view"; import { View, AddChildFromBuilder, Property, CssProperty, InheritedCssProperty, Style, Length } from "ui/core/view";
import { FormattedString, FormattedStringView } from "text/formatted-string"; import { FormattedString } from "text/formatted-string";
export * from "ui/core/view"; export * from "ui/core/view";
export { FormattedString, FormattedStringView } from "text/formatted-string"; export { FormattedString } from "text/formatted-string";
/** /**
* Represents the base class for all text views. * Represents the base class for all text views.
*/ */
export class TextBase extends View implements AddChildFromBuilder, FormattedStringView { export class TextBase extends View implements AddChildFromBuilder {
/** /**
* Gets or sets the text. * Gets or sets the text.
*/ */