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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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.
*/