mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Enable Button tests, fix AbsoluteLayout tests
This commit is contained in:
@ -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<viewModule.View>) {
|
||||
// TKUnit.assertEqual(view.text, "");
|
||||
var view = new buttonModule.Button();
|
||||
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
|
||||
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<viewModule.View>) {
|
||||
// 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<viewModule.View>) {
|
||||
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<viewModule.View>) {
|
||||
// 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<viewModule.View>) {
|
||||
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");
|
||||
});
|
||||
}
|
||||
|
@ -377,32 +377,6 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
||||
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;
|
||||
|
@ -82,27 +82,26 @@ export class AbsoluteLayoutTest extends testModule.UITest<absoluteLayoutModule.A
|
||||
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() {
|
||||
// let layout = this.testView;
|
||||
// layout.width = { value: 200, unit: "px" };
|
||||
// layout.height = { value: 200, unit: "px" };
|
||||
public test_percent_children_support() {
|
||||
let layout = this.testView;
|
||||
layout.width = { value: 200, unit: "px" };
|
||||
layout.height = { value: 200, unit: "px" };
|
||||
|
||||
// let btn = new layoutHelper.MyButton();
|
||||
// (<any>btn).width = "50%";
|
||||
// (<any>btn).height = "50%";
|
||||
// btn.margin = "10%";
|
||||
// layout.addChild(btn);
|
||||
let btn = new layoutHelper.MyButton();
|
||||
(<any>btn).width = "50%";
|
||||
(<any>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);
|
||||
|
@ -159,30 +159,21 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout>
|
||||
}, "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<RemovalTrackingGridLayout>
|
||||
}
|
||||
}
|
||||
|
||||
// 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, <any>"unsupported");
|
||||
// }, "'ItemSpec type' incorrect value.");
|
||||
// }
|
||||
public test_ItemSpec_constructor_throws_onWrongType() {
|
||||
TKUnit.assertThrows(() => {
|
||||
return new ItemSpec(1, <any>"unsupported");
|
||||
}, "Invalid value: unsupported");
|
||||
}
|
||||
|
||||
public test_ItemSpec_auto() {
|
||||
var w = new ItemSpec(1, "auto");
|
||||
|
@ -946,9 +946,13 @@ export function makeValidator<T>(...values: T[]): (value: any) => value is T {
|
||||
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 => {
|
||||
const lower = value && value.toLowerCase();
|
||||
return isValid(lower) ? lower : def;
|
||||
if (isValid(lower)) {
|
||||
return lower;
|
||||
} else {
|
||||
throw new Error("Invalid value: " + value);
|
||||
}
|
||||
}
|
||||
}
|
@ -1237,7 +1237,7 @@ export namespace HorizontalAlignment {
|
||||
export const RIGHT: "right" = "right";
|
||||
export const STRETCH: "stretch" = "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 });
|
||||
@ -1250,7 +1250,16 @@ export namespace VerticalAlignment {
|
||||
export const BOTTOM: "bottom" = "bottom";
|
||||
export const STRETCH: "stretch" = "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 });
|
||||
@ -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<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>({
|
||||
@ -2016,7 +2025,7 @@ export namespace Visibility {
|
||||
export const HIDDEN: "hidden" = "hidden";
|
||||
export const COLLAPSE: "collapse" = "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>({
|
||||
@ -2024,4 +2033,4 @@ export const visibilityProperty = new CssProperty<Style, Visibility>({
|
||||
target.view.isCollapsed = (newValue === Visibility.COLLAPSE);
|
||||
}
|
||||
});
|
||||
visibilityProperty.register(Style);
|
||||
visibilityProperty.register(Style);
|
||||
|
2
tns-core-modules/ui/definitions.d.ts
vendored
2
tns-core-modules/ui/definitions.d.ts
vendored
@ -270,5 +270,5 @@ declare module "ui/core/properties" {
|
||||
export function resetCSSProperties(style: Style): void;
|
||||
|
||||
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;
|
||||
}
|
@ -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);
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ export namespace FlexDirection {
|
||||
export const COLUMN_REVERSE: "column-reverse" = "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";
|
||||
@ -45,7 +45,7 @@ export namespace FlexWrap {
|
||||
export const WRAP_REVERSE: "wrap-reverse" = "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";
|
||||
@ -57,7 +57,7 @@ export namespace JustifyContent {
|
||||
export const SPACE_AROUND: "space-around" = "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;
|
||||
@ -74,7 +74,7 @@ export namespace AlignItems {
|
||||
export const STRETCH: "stretch" = "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";
|
||||
@ -87,7 +87,7 @@ export namespace AlignContent {
|
||||
export const STRETCH: "stretch" = "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;
|
||||
@ -143,7 +143,7 @@ export namespace AlignSelf {
|
||||
export const STRETCH: "stretch" = "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 {
|
||||
|
@ -368,5 +368,5 @@ export namespace GridUnitType {
|
||||
export const STAR: "star" = "star";
|
||||
export const AUTO: "auto" = "auto";
|
||||
export const isValid = makeValidator<GridUnitType>(PIXEL, STAR, AUTO);
|
||||
export const parse = makeParser(isValid, undefined);
|
||||
export const parse = makeParser<GridUnitType>(isValid);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ export namespace FontStyle {
|
||||
export const NORMAL: "normal" = "normal";
|
||||
export const ITALIC: "italic" = "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";
|
||||
@ -65,7 +65,7 @@ export namespace FontWeight {
|
||||
export const EXTRA_BOLD: "800" = "800";
|
||||
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 parse = makeParser(isValid, NORMAL);
|
||||
export const parse = makeParser<FontStyle>(isValid);
|
||||
}
|
||||
|
||||
export function parseFontFamily(value: string): Array<string> {
|
||||
|
@ -152,7 +152,7 @@ export namespace TextAlignment {
|
||||
export const CENTER: "center" = "center";
|
||||
export const RIGHT: "right" = "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>({
|
||||
@ -171,7 +171,7 @@ export namespace TextDecoration {
|
||||
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 parse = makeParser(isValid, NONE);
|
||||
export const parse = makeParser<TextDecoration>(isValid);
|
||||
}
|
||||
export const textDecorationProperty = new CssProperty<Style, TextDecoration>({
|
||||
name: "textDecoration",
|
||||
@ -189,7 +189,7 @@ export namespace TextTransform {
|
||||
export const UPPERCASE: "uppercase" = "uppercase";
|
||||
export const LOWERCASE: "lowercase" = "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>({
|
||||
name: "textTransform",
|
||||
@ -205,7 +205,7 @@ export namespace WhiteSpace {
|
||||
export const NORMAL: "normal" = "normal";
|
||||
export const NO_WRAP: "nowrap" = "nowrap";
|
||||
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
|
||||
|
@ -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<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> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
tns-core-modules/ui/text-base/text-base.d.ts
vendored
6
tns-core-modules/ui/text-base/text-base.d.ts
vendored
@ -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.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user