diff --git a/tests/app/ui/button/button-tests.ts b/tests/app/ui/button/button-tests.ts index 4d26f5486..f5b6b053c 100644 --- a/tests/app/ui/button/button-tests.ts +++ b/tests/app/ui/button/button-tests.ts @@ -4,9 +4,8 @@ import * as viewModule from "ui/core/view"; import * as pagesModule from "ui/page"; import * as buttonTestsNative from "./button-tests-native"; import * as colorModule from "color"; -// import * as enums from "ui/enums"; -// import * as formattedStringModule from "text/formatted-string"; -// import * as spanModule from "text/span"; +import * as formattedStringModule from "text/formatted-string"; +import * as spanModule from "text/span"; // >> button-require 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 () { -// var firstSpan = new spanModule.Span(); -// firstSpan.fontSize = 10; -// firstSpan.text = "First"; -// var secondSpan = new spanModule.Span(); -// secondSpan.fontSize = 15; -// secondSpan.text = "Second"; -// var thirdSpan = new spanModule.Span(); -// thirdSpan.fontSize = 20; -// thirdSpan.text = "Third"; -// var formattedString1 = new formattedStringModule.FormattedString(); -// formattedString1.spans.push(firstSpan); -// var formattedString2 = new formattedStringModule.FormattedString(); -// formattedString2.spans.push(secondSpan); -// formattedString2.spans.push(thirdSpan); +export var test_WhenFormattedTextPropertyChanges_TextIsUpdated_Button = function () { + var firstSpan = new spanModule.Span(); + firstSpan.fontSize = 10; + firstSpan.text = "First"; + var secondSpan = new spanModule.Span(); + secondSpan.fontSize = 15; + secondSpan.text = "Second"; + var thirdSpan = new spanModule.Span(); + thirdSpan.fontSize = 20; + thirdSpan.text = "Third"; + var formattedString1 = new formattedStringModule.FormattedString(); + formattedString1.spans.push(firstSpan); + var formattedString2 = new formattedStringModule.FormattedString(); + formattedString2.spans.push(secondSpan); + formattedString2.spans.push(thirdSpan); -// var view = new buttonModule.Button(); -// helper.buildUIAndRunTest(view, function (views: Array) { -// TKUnit.assertEqual(view.text, ""); + var view = new buttonModule.Button(); + helper.buildUIAndRunTest(view, function (views: Array) { + TKUnit.assertEqual(view.text, ""); -// view.formattedText = formattedString1; -// TKUnit.assertEqual(view.text, "First"); + view.formattedText = formattedString1; + TKUnit.assertEqual(view.text, "First"); -// view.formattedText = formattedString2; -// TKUnit.assertEqual(view.text, "SecondThird"); + view.formattedText = formattedString2; + TKUnit.assertEqual(view.text, "SecondThird"); -// formattedString2.spans.getItem(0).text = "Mecond"; -// TKUnit.assertEqual(view.text, "MecondThird"); + formattedString2.spans.getItem(0).text = "Mecond"; + TKUnit.assertEqual(view.text, "MecondThird"); -// view.formattedText = null; -// TKUnit.assertEqual(view.text, ""); -// }); -// } + view.formattedText = null; + TKUnit.assertEqual(view.text, ""); + }); +} -// export function test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormattedText_DoesNotCrash() { -// let view = new buttonModule.Button(); -// helper.buildUIAndRunTest(view, function (views: Array) { -// view.text = "NormalText"; -// view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;"); - -// TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.uppercase, "TextTransform"); -// TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.underline, "TextDecoration"); -// TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing"); -// }); -// } +export function test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormattedText_DoesNotCrash() { + let view = new buttonModule.Button(); + helper.buildUIAndRunTest(view, function (views: Array) { + view.text = "NormalText"; + view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;"); -// export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedText_DoesNotCrash() { -// let view = new buttonModule.Button(); -// let formattedString = helper._generateFormattedString(); -// helper.buildUIAndRunTest(view, function (views: Array) { -// view.formattedText = formattedString; -// view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;"); - -// TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.uppercase, "TextTransform"); -// TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.underline, "TextDecoration"); -// TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing"); -// }); -// } + TKUnit.assertEqual(view.style.textTransform, "uppercase", "TextTransform"); + TKUnit.assertEqual(view.style.textDecoration, "underline", "TextDecoration"); + TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing"); + }); +} + +export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedText_DoesNotCrash() { + let view = new buttonModule.Button(); + let formattedString = helper._generateFormattedString(); + helper.buildUIAndRunTest(view, function (views: Array) { + view.formattedText = formattedString; + view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;"); + + TKUnit.assertEqual(view.style.textTransform, "uppercase", "TextTransform"); + TKUnit.assertEqual(view.style.textDecoration, "underline", "TextDecoration"); + TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing"); + }); +} diff --git a/tests/app/ui/label/label-tests.ts b/tests/app/ui/label/label-tests.ts index 8b0afa1ae..d96c3b505 100644 --- a/tests/app/ui/label/label-tests.ts +++ b/tests/app/ui/label/label-tests.ts @@ -377,32 +377,6 @@ export class LabelTest extends testModule.UITest { 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"; public testLocalTextAlignmentFromCss() { const label = this.testView; diff --git a/tests/app/ui/layouts/absolute-layout-tests.ts b/tests/app/ui/layouts/absolute-layout-tests.ts index 449317d30..f02c8227a 100644 --- a/tests/app/ui/layouts/absolute-layout-tests.ts +++ b/tests/app/ui/layouts/absolute-layout-tests.ts @@ -82,27 +82,26 @@ export class AbsoluteLayoutTest extends testModule.UITestbtn).width = "50%"; - // (btn).height = "50%"; - // btn.margin = "10%"; - // layout.addChild(btn); + let btn = new layoutHelper.MyButton(); + (btn).width = "50%"; + (btn).height = "50%"; + btn.margin = "10%"; + layout.addChild(btn); - // this.waitUntilTestElementLayoutIsValid(); + this.waitUntilTestElementLayoutIsValid(); - // // AbsoluteLayout measures with 0/UNSPECIFIED so we cannot support percents in it. - // layoutHelper.assertMeasure(btn, 100, 100); - // layoutHelper.assertLayout(btn, 20, 20, btn.getMeasuredWidth(), btn.getMeasuredHeight()); + // AbsoluteLayout measures with 0/UNSPECIFIED so we cannot support percents in it. + layoutHelper.assertMeasure(btn, 100, 100); + layoutHelper.assertLayout(btn, 20, 20, btn.getMeasuredWidth(), btn.getMeasuredHeight()); - // TKUnit.assertEqual(btn.getMeasuredWidth(), 100, "Button MeasuredWidth incorrect"); - // TKUnit.assertEqual(btn.getMeasuredHeight(), 100, "Button MeasuredHeight incorrect"); - // } + TKUnit.assertEqual(btn.getMeasuredWidth(), 100, "Button MeasuredWidth incorrect"); + TKUnit.assertEqual(btn.getMeasuredHeight(), 100, "Button MeasuredHeight incorrect"); + } public test_percent_support_nativeLayoutParams_are_correct() { commonTests.percent_support_nativeLayoutParams_are_correct(this); diff --git a/tests/app/ui/layouts/grid-layout-tests.ts b/tests/app/ui/layouts/grid-layout-tests.ts index d48100cf6..cf696e580 100644 --- a/tests/app/ui/layouts/grid-layout-tests.ts +++ b/tests/app/ui/layouts/grid-layout-tests.ts @@ -159,30 +159,21 @@ export class GridLayoutTest extends testModule.UITest }, "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_shouldThrow_onNegativeValues() { - // TKUnit.assertThrows(() => { - // GridLayout.setRow(new Button(), -1); - // }, "setRow should throw when value < 0"); - // } + public test_setRow_shouldNotThrow_onNegativeValues() { + GridLayout.setRow(new Button(), -1); + } - // public test_setRowSpan_shouldThrow_onNotPositiveValues() { - // TKUnit.assertThrows(() => { - // GridLayout.setRowSpan(new Button(), 0); - // }, "setRowSpan should throw when value <= 0"); - // } + public test_setRowSpan_shouldNotThrow_onNotPositiveValues() { + GridLayout.setRowSpan(new Button(), 0); + } - // public test_setColumn_shouldThrow_onNegativeValues() { - // TKUnit.assertThrows(() => { - // GridLayout.setColumn(new Button(), -1); - // }, "setColumn should when value < 0"); - // } + public test_setColumn_shouldNotThrow_onNegativeValues() { + GridLayout.setColumn(new Button(), -1); + } - // public test_setColumnSpan_shouldThrow_onNotPositiveValues() { - // TKUnit.assertThrows(() => { - // GridLayout.setColumnSpan(new Button(), 0); - // }, "setColumnSpan should throw when value <= 0"); - // } + public test_setColumnSpan_shouldNotThrow_onNotPositiveValues() { + GridLayout.setColumnSpan(new Button(), 0); + } public test_addRow_shouldThrow_onNullValues() { TKUnit.assertThrows(() => { @@ -325,12 +316,11 @@ export class GridLayoutTest extends testModule.UITest } } - // TODO: This used to throw but the underlaying "makeParser" used fallbacks to default value instead of throwing - // public test_ItemSpec_constructor_throws_onWrongType() { - // TKUnit.assertThrows(() => { - // return new ItemSpec(1, "unsupported"); - // }, "'ItemSpec type' incorrect value."); - // } + public test_ItemSpec_constructor_throws_onWrongType() { + TKUnit.assertThrows(() => { + return new ItemSpec(1, "unsupported"); + }, "Invalid value: unsupported"); + } public test_ItemSpec_auto() { var w = new ItemSpec(1, "auto"); diff --git a/tns-core-modules/ui/core/properties.ts b/tns-core-modules/ui/core/properties.ts index f5015ebc1..8b432faca 100644 --- a/tns-core-modules/ui/core/properties.ts +++ b/tns-core-modules/ui/core/properties.ts @@ -946,9 +946,13 @@ export function makeValidator(...values: T[]): (value: any) => value is T { return (value: any): value is T => set.has(value); } -export function makeParser(isValid: (value: any) => boolean, def: T): (value: any) => T { +export function makeParser(isValid: (value: any) => boolean): (value: any) => T { return value => { const lower = value && value.toLowerCase(); - return isValid(lower) ? lower : def; + if (isValid(lower)) { + return lower; + } else { + throw new Error("Invalid value: " + value); + } } } \ No newline at end of file diff --git a/tns-core-modules/ui/core/view-common.ts b/tns-core-modules/ui/core/view-common.ts index bedd745c5..f0e55d371 100644 --- a/tns-core-modules/ui/core/view-common.ts +++ b/tns-core-modules/ui/core/view-common.ts @@ -1237,7 +1237,7 @@ export namespace HorizontalAlignment { export const RIGHT: "right" = "right"; export const STRETCH: "stretch" = "stretch"; export const isValid = makeValidator(LEFT, CENTER, RIGHT, STRETCH); - export const parse = makeParser(isValid, STRETCH); + export const parse = makeParser(isValid); } export const horizontalAlignmentProperty = new CssProperty({ 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 STRETCH: "stretch" = "stretch"; export const isValid = makeValidator(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({ 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 NO_REPEAT: "no-repeat" = "no-repeat"; export const isValid = makeValidator(REPEAT, REPEAT_X, REPEAT_Y, NO_REPEAT); - export const parse = makeParser(isValid, undefined); + export const parse = makeParser(isValid); } export const backgroundRepeatProperty = new CssProperty({ @@ -2016,7 +2025,7 @@ export namespace Visibility { export const HIDDEN: "hidden" = "hidden"; export const COLLAPSE: "collapse" = "collapse"; export const isValid = makeValidator(VISIBLE, HIDDEN, COLLAPSE); - export const parse = makeParser(isValid, VISIBLE); + export const parse = makeParser(isValid); } export const visibilityProperty = new CssProperty({ @@ -2024,4 +2033,4 @@ export const visibilityProperty = new CssProperty({ target.view.isCollapsed = (newValue === Visibility.COLLAPSE); } }); -visibilityProperty.register(Style); \ No newline at end of file +visibilityProperty.register(Style); diff --git a/tns-core-modules/ui/definitions.d.ts b/tns-core-modules/ui/definitions.d.ts index a61b5a1f9..be46d5bbb 100644 --- a/tns-core-modules/ui/definitions.d.ts +++ b/tns-core-modules/ui/definitions.d.ts @@ -270,5 +270,5 @@ declare module "ui/core/properties" { export function resetCSSProperties(style: Style): void; export function makeValidator(...values: T[]): (value: any) => value is T; - export function makeParser(isValid: (value: any) => boolean, def: T): (value: any) => T; + export function makeParser(isValid: (value: any) => boolean): (value: any) => T; } \ No newline at end of file diff --git a/tns-core-modules/ui/layouts/absolute-layout/absolute-layout.ios.ts b/tns-core-modules/ui/layouts/absolute-layout/absolute-layout.ios.ts index f318c1199..98420b2cc 100644 --- a/tns-core-modules/ui/layouts/absolute-layout/absolute-layout.ios.ts +++ b/tns-core-modules/ui/layouts/absolute-layout/absolute-layout.ios.ts @@ -54,8 +54,8 @@ export class AbsoluteLayout extends AbsoluteLayoutBase { const childLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + child.effectiveLeft; const childTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + child.effectiveTop; - const childRight = childLeft + childWidth + this.effectiveMarginLeft + this.effectiveMarginRight; - const childBottom = childTop + childHeight + this.effectiveMarginTop + this.effectiveMarginBottom; + const childRight = childLeft + childWidth + child.effectiveMarginLeft + child.effectiveMarginRight; + const childBottom = childTop + childHeight + child.effectiveMarginTop + child.effectiveMarginBottom; View.layoutChild(this, child, childLeft, childTop, childRight, childBottom); }); diff --git a/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout-common.ts b/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout-common.ts index 0d6594952..23ca718c2 100644 --- a/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout-common.ts +++ b/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout-common.ts @@ -35,7 +35,7 @@ export namespace FlexDirection { export const COLUMN_REVERSE: "column-reverse" = "column-reverse"; export const isValid = makeValidator(ROW, ROW_REVERSE, COLUMN, COLUMN_REVERSE); - export const parse = makeParser(isValid, ROW); + export const parse = makeParser(isValid); } export type FlexWrap = "nowrap" | "wrap" | "wrap-reverse"; @@ -45,7 +45,7 @@ export namespace FlexWrap { export const WRAP_REVERSE: "wrap-reverse" = "wrap-reverse"; export const isValid = makeValidator(NOWRAP, WRAP, WRAP_REVERSE); - export const parse = makeParser(isValid, NOWRAP); + export const parse = makeParser(isValid); } 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 isValid = makeValidator(FLEX_START, FLEX_END, CENTER, SPACE_BETWEEN, SPACE_AROUND); - export const parse = makeParser(isValid, FLEX_START); + export const parse = makeParser(isValid); } export type FlexBasisPercent = number; @@ -74,7 +74,7 @@ export namespace AlignItems { export const STRETCH: "stretch" = "stretch"; export const isValid = makeValidator(FLEX_START, FLEX_END, CENTER, BASELINE, STRETCH); - export const parse = makeParser(isValid, FLEX_START); + export const parse = makeParser(isValid); } 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 isValid = makeValidator(FLEX_START, FLEX_END, CENTER, SPACE_BETWEEN, SPACE_AROUND, STRETCH); - export const parse = makeParser(isValid, FLEX_START); + export const parse = makeParser(isValid); } export type Order = number; @@ -143,7 +143,7 @@ export namespace AlignSelf { export const STRETCH: "stretch" = "stretch"; export const isValid = makeValidator(AUTO, FLEX_START, FLEX_END, CENTER, BASELINE, STRETCH); - export const parse = makeParser(isValid, AUTO); + export const parse = makeParser(isValid); } function validateArgs(element: View): View { diff --git a/tns-core-modules/ui/layouts/grid-layout/grid-layout-common.ts b/tns-core-modules/ui/layouts/grid-layout/grid-layout-common.ts index f705b6aed..d187e80ac 100644 --- a/tns-core-modules/ui/layouts/grid-layout/grid-layout-common.ts +++ b/tns-core-modules/ui/layouts/grid-layout/grid-layout-common.ts @@ -368,5 +368,5 @@ export namespace GridUnitType { export const STAR: "star" = "star"; export const AUTO: "auto" = "auto"; export const isValid = makeValidator(PIXEL, STAR, AUTO); - export const parse = makeParser(isValid, undefined); + export const parse = makeParser(isValid); } diff --git a/tns-core-modules/ui/styling/font-common.ts b/tns-core-modules/ui/styling/font-common.ts index 88e2bb91b..e3fa2b6a6 100644 --- a/tns-core-modules/ui/styling/font-common.ts +++ b/tns-core-modules/ui/styling/font-common.ts @@ -50,7 +50,7 @@ export namespace FontStyle { export const NORMAL: "normal" = "normal"; export const ITALIC: "italic" = "italic"; export const isValid = makeValidator(NORMAL, ITALIC); - export const parse = makeParser(isValid, NORMAL); + export const parse = makeParser(isValid); } 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 BLACK: "900" = "900"; export const isValid = makeValidator(THIN, EXTRA_LIGHT, LIGHT, NORMAL, "400", MEDIUM, SEMI_BOLD, BOLD, "700", EXTRA_BOLD, BLACK); - export const parse = makeParser(isValid, NORMAL); + export const parse = makeParser(isValid); } export function parseFontFamily(value: string): Array { diff --git a/tns-core-modules/ui/text-base/text-base-common.ts b/tns-core-modules/ui/text-base/text-base-common.ts index fed1c1977..cfafac04e 100644 --- a/tns-core-modules/ui/text-base/text-base-common.ts +++ b/tns-core-modules/ui/text-base/text-base-common.ts @@ -152,7 +152,7 @@ export namespace TextAlignment { export const CENTER: "center" = "center"; export const RIGHT: "right" = "right"; export const isValid = makeValidator(LEFT, CENTER, RIGHT); - export const parse = makeParser(isValid, undefined); + export const parse = makeParser(isValid); } export const textAlignmentProperty = new InheritedCssProperty({ @@ -171,7 +171,7 @@ export namespace TextDecoration { export const UNDERLINE_LINE_THROUGH: "underline line-through" = "underline line-through"; export const isValid = makeValidator(NONE, UNDERLINE, LINE_THROUGH, UNDERLINE_LINE_THROUGH); - export const parse = makeParser(isValid, NONE); + export const parse = makeParser(isValid); } export const textDecorationProperty = new CssProperty({ name: "textDecoration", @@ -189,7 +189,7 @@ export namespace TextTransform { export const UPPERCASE: "uppercase" = "uppercase"; export const LOWERCASE: "lowercase" = "lowercase"; export const isValid = makeValidator(NONE, CAPITALIZE, UPPERCASE, LOWERCASE); - export const parse = makeParser(isValid, NONE); + export const parse = makeParser(isValid); } export const textTransformProperty = new CssProperty({ name: "textTransform", @@ -205,7 +205,7 @@ export namespace WhiteSpace { export const NORMAL: "normal" = "normal"; export const NO_WRAP: "nowrap" = "nowrap"; export const isValid = makeValidator(NORMAL, NO_WRAP); - export const parse = makeParser(isValid, NORMAL); + export const parse = makeParser(isValid); } //NB: Default value is deferent for Android and IOS diff --git a/tns-core-modules/ui/text-base/text-base.android.ts b/tns-core-modules/ui/text-base/text-base.android.ts index ed7fb1ad3..e8ab1f67d 100644 --- a/tns-core-modules/ui/text-base/text-base.android.ts +++ b/tns-core-modules/ui/text-base/text-base.android.ts @@ -48,7 +48,7 @@ export class TextBase extends TextBaseCommon { } set [textTransformProperty.native](value: TextTransform | android.text.method.TransformationMethod) { if (typeof value === "string") { - this._nativeView.setTransformationMethod(new TextTransformation(this.text, this.formattedText, value)); + this._nativeView.setTransformationMethod(new TextTransformation(this)); } else { this._nativeView.setTransformationMethod(value); } @@ -207,36 +207,39 @@ export class TextBase extends TextBaseCommon { @Interfaces([android.text.method.TransformationMethod]) class TextTransformation extends android.text.method.ReplacementTransformationMethod { - constructor(public originalText: string, public formattedText: FormattedString, public textTransform: TextTransform) { + constructor(public textBase: TextBase) { super(); return global.__native(this); } protected getOriginal(): native.Array { - 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 { let replacementString: string = ""; - if (this.formattedText) { - for (let i = 0, length = this.formattedText.spans.length; i < length; i++) { - let span = this.formattedText.spans.getItem(i); - replacementString += getTransformedText(span.text, this.textTransform); + const formattedText = this.textBase.formattedText; + const textTransform = this.textBase.textTransform; + if (formattedText) { + for (let i = 0, length = formattedText.spans.length; i < length; i++) { + let span = formattedText.spans.getItem(i); + replacementString += getTransformedText(span.text, textTransform); } } else { - replacementString = getTransformedText(this.originalText, this.textTransform); + replacementString = getTransformedText(this.textBase.text, textTransform); } return convertStringToNativeCharArray(replacementString); } public getTransformation(charSeq: any, view: android.view.View): any { - if (this.formattedText) { - return createSpannableStringBuilder(this.formattedText); + const formattedText = this.textBase.formattedText; + if (formattedText) { + return createSpannableStringBuilder(formattedText); } else { - return getTransformedText(this.originalText, this.textTransform); + return getTransformedText(this.textBase.text, this.textBase.textTransform); } } } diff --git a/tns-core-modules/ui/text-base/text-base.d.ts b/tns-core-modules/ui/text-base/text-base.d.ts index 6074a8236..55cc47116 100644 --- a/tns-core-modules/ui/text-base/text-base.d.ts +++ b/tns-core-modules/ui/text-base/text-base.d.ts @@ -1,14 +1,14 @@ declare module "ui/text-base" { 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 { FormattedString, FormattedStringView } from "text/formatted-string"; + export { FormattedString } from "text/formatted-string"; /** * 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. */