This commit is contained in:
Hristo Hristov
2016-12-06 01:42:30 +02:00
committed by Hristo Hristov
parent da4cad6ec2
commit 94dee2973a
11 changed files with 226 additions and 158 deletions

View File

@ -19,26 +19,26 @@ export abstract class EditableTextBase extends TextBase implements EditableTextB
public abstract dismissSoftInput(); public abstract dismissSoftInput();
} }
export let placeholderColorProperty = new CssProperty<Style, Color>({ name: "placeholderColor", cssName: "placeholder-color", equalityComparer: Color.equals, valueConverter: (v: string) => new Color(v) }); export const placeholderColorProperty = new CssProperty<Style, Color>({ name: "placeholderColor", cssName: "placeholder-color", equalityComparer: Color.equals, valueConverter: (v: string) => new Color(v) });
placeholderColorProperty.register(Style); placeholderColorProperty.register(Style);
export let keyboardTypeProperty = new Property<EditableTextBase, "datetime" | "phone" | "number" | "url" | "email">({ name: "keyboardType" }); export const keyboardTypeProperty = new Property<EditableTextBase, "datetime" | "phone" | "number" | "url" | "email">({ name: "keyboardType" });
keyboardTypeProperty.register(EditableTextBase); keyboardTypeProperty.register(EditableTextBase);
export let returnKeyTypeProperty = new Property<EditableTextBase, "done" | "next" | "go" | "search" | "send">({ name: "returnKeyType" }); export const returnKeyTypeProperty = new Property<EditableTextBase, "done" | "next" | "go" | "search" | "send">({ name: "returnKeyType" });
returnKeyTypeProperty.register(EditableTextBase); returnKeyTypeProperty.register(EditableTextBase);
export let editableProperty = new Property<EditableTextBase, boolean>({ name: "editable", defaultValue: true }); export const editableProperty = new Property<EditableTextBase, boolean>({ name: "editable", defaultValue: true });
editableProperty.register(EditableTextBase); editableProperty.register(EditableTextBase);
export let updateTextTriggerProperty = new Property<EditableTextBase, "focusLost" | "textChanged">({ name: "updateTextTrigger", defaultValue: "textChanged" }); export const updateTextTriggerProperty = new Property<EditableTextBase, "focusLost" | "textChanged">({ name: "updateTextTrigger", defaultValue: "textChanged" });
updateTextTriggerProperty.register(EditableTextBase); updateTextTriggerProperty.register(EditableTextBase);
export let autocapitalizationTypeProperty = new Property<EditableTextBase, "none" | "words" | "sentences" | "allCharacters">({ name: "autocapitalizationType", defaultValue: "sentences" }); export const autocapitalizationTypeProperty = new Property<EditableTextBase, "none" | "words" | "sentences" | "allCharacters">({ name: "autocapitalizationType", defaultValue: "sentences" });
autocapitalizationTypeProperty.register(EditableTextBase); autocapitalizationTypeProperty.register(EditableTextBase);
export let autocorrectProperty = new Property<EditableTextBase, boolean>({ name: "autocorrect" }); export const autocorrectProperty = new Property<EditableTextBase, boolean>({ name: "autocorrect" });
autocorrectProperty.register(EditableTextBase); autocorrectProperty.register(EditableTextBase);
export let hintProperty = new Property<EditableTextBase, string>({ name: "hint", defaultValue: "" }); export const hintProperty = new Property<EditableTextBase, string>({ name: "hint", defaultValue: "" });
hintProperty.register(EditableTextBase); hintProperty.register(EditableTextBase);

View File

@ -1,15 +1,17 @@
declare module "ui/editable-text-base" { declare module "ui/editable-text-base" {
import { Property } from "ui/core/properties"; import { Property, CssProperty } from "ui/core/properties";
import { TextBase } from "ui/text-base"; import { TextBase } from "ui/text-base";
import { Style } from "ui/styling/style";
import { Color } from "color";
export let keyboardTypeProperty: Property<EditableTextBase, string>; export const keyboardTypeProperty: Property<EditableTextBase, string>;
export let returnKeyTypeProperty: Property<EditableTextBase, string>; export const returnKeyTypeProperty: Property<EditableTextBase, string>;
export let editableProperty: Property<EditableTextBase, boolean>; export const editableProperty: Property<EditableTextBase, boolean>;
export let updateTextTriggerProperty: Property<EditableTextBase, string>; export const updateTextTriggerProperty: Property<EditableTextBase, string>;
export let autocapitalizationTypeProperty: Property<EditableTextBase, string>; export const autocapitalizationTypeProperty: Property<EditableTextBase, string>;
export let autocorrectProperty: Property<EditableTextBase, boolean>; export const autocorrectProperty: Property<EditableTextBase, boolean>;
export let hintProperty: Property<EditableTextBase, string>; export const hintProperty: Property<EditableTextBase, string>;
export const placeholderColorProperty: CssProperty<Style, Color>;
/** /**
* Represents the base class for all editable text views. * Represents the base class for all editable text views.
*/ */
@ -17,7 +19,7 @@
/** /**
* Gets or sets the soft keyboard type. Possible values are contained in the [KeyboardType enumeration](../enums/KeyboardType/README.md). * Gets or sets the soft keyboard type. Possible values are contained in the [KeyboardType enumeration](../enums/KeyboardType/README.md).
*/ */
keyboardType: "datetime"| "phone" | "number" | "url" | "email"; keyboardType: "datetime" | "phone" | "number" | "url" | "email";
/** /**
* Gets or sets the soft keyboard return key flavor. Possible values are contained in the [ReturnKeyType enumeration](../enums/ReturnKeyType/README.md). * Gets or sets the soft keyboard return key flavor. Possible values are contained in the [ReturnKeyType enumeration](../enums/ReturnKeyType/README.md).
@ -55,4 +57,6 @@
*/ */
dismissSoftInput(): void; dismissSoftInput(): void;
} }
export * from "ui/text-base";
} }

View File

@ -116,13 +116,13 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition,
} }
} }
export let textProperty = new Property<TextBaseCommon, string>({ name: "text", defaultValue: "" }); export const textProperty = new Property<TextBaseCommon, string>({ name: "text", defaultValue: "" });
textProperty.register(TextBaseCommon); textProperty.register(TextBaseCommon);
export let formattedTextProperty = new Property<TextBaseCommon, FormattedString>({ name: "formattedText", affectsLayout: isIOS, valueChanged: onFormattedTextPropertyChanged }); export const formattedTextProperty = new Property<TextBaseCommon, FormattedString>({ name: "formattedText", affectsLayout: isIOS, valueChanged: onFormattedTextPropertyChanged });
formattedTextProperty.register(TextBaseCommon); formattedTextProperty.register(TextBaseCommon);
export let textAlignmentProperty = new InheritedCssProperty<Style, "left" | "center" | "right">({ export const textAlignmentProperty = new InheritedCssProperty<Style, "left" | "center" | "right">({
name: "textAlignment", cssName: "text-align", valueConverter: (value) => { name: "textAlignment", cssName: "text-align", valueConverter: (value) => {
switch (value) { switch (value) {
case "left": case "left":
@ -137,7 +137,7 @@ export let textAlignmentProperty = new InheritedCssProperty<Style, "left" | "cen
}); });
textAlignmentProperty.register(Style); textAlignmentProperty.register(Style);
export let textDecorationProperty = new CssProperty<Style, "none" | "underline" | "line-through">({ export const textDecorationProperty = new CssProperty<Style, "none" | "underline" | "line-through">({
name: "textDecoration", cssName: "text-decoration", defaultValue: "none", valueConverter: (value) => { name: "textDecoration", cssName: "text-decoration", defaultValue: "none", valueConverter: (value) => {
let values = (value + "").split(" "); let values = (value + "").split(" ");
@ -150,7 +150,7 @@ export let textDecorationProperty = new CssProperty<Style, "none" | "underline"
}); });
textDecorationProperty.register(Style); textDecorationProperty.register(Style);
export let textTransformProperty = new CssProperty<Style, "none" | "capitalize" | "uppercase" | "lowercase">({ export const textTransformProperty = new CssProperty<Style, "none" | "capitalize" | "uppercase" | "lowercase">({
name: "textTransform", cssName: "text-transform", defaultValue: "none", valueConverter: (value) => { name: "textTransform", cssName: "text-transform", defaultValue: "none", valueConverter: (value) => {
switch (value) { switch (value) {
case "none": case "none":
@ -166,7 +166,7 @@ export let textTransformProperty = new CssProperty<Style, "none" | "capitalize"
}); });
textTransformProperty.register(Style); textTransformProperty.register(Style);
export let whiteSpaceProperty = new CssProperty<Style, "normal" | "nowrap">({ export const whiteSpaceProperty = new CssProperty<Style, "normal" | "nowrap">({
name: "whiteSpace", cssName: "white-space", valueConverter: (value: "normal" | "nowrap") => { name: "whiteSpace", cssName: "white-space", valueConverter: (value: "normal" | "nowrap") => {
switch (value) { switch (value) {
case "normal": case "normal":
@ -179,5 +179,5 @@ export let whiteSpaceProperty = new CssProperty<Style, "normal" | "nowrap">({
}); });
whiteSpaceProperty.register(Style); whiteSpaceProperty.register(Style);
export let letterSpacingProperty = new CssProperty<Style, number>({ name: "letterSpacing", cssName: "letter-spacing", defaultValue: 0, affectsLayout: isIOS, valueConverter: (v: string) => parseFloat(v) }); export const letterSpacingProperty = new CssProperty<Style, number>({ name: "letterSpacing", cssName: "letter-spacing", defaultValue: 0, affectsLayout: isIOS, valueConverter: (v: string) => parseFloat(v) });
letterSpacingProperty.register(Style); letterSpacingProperty.register(Style);

View File

@ -1,11 +1,10 @@
import { TextBaseCommon, textProperty, formattedTextProperty } from "./text-base-common"; import {
TextBaseCommon, textProperty, formattedTextProperty, textAlignmentProperty, textDecorationProperty,
textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty, whiteSpaceProperty
} from "./text-base-common";
import { FormattedString } from "text/formatted-string"; import { FormattedString } from "text/formatted-string";
import { import { Font } from "ui/styling/font";
colorProperty, fontInternalProperty, textAlignmentProperty, textDecorationProperty, import { Color } from "color";
textTransformProperty, whiteSpaceProperty, letterSpacingProperty
} from "ui/styling/style";
import { TextAlignment, TextDecoration, TextTransform, WhiteSpace } from "ui/enums";
import { toUIString } from "utils/types";
export * from "./text-base-common"; export * from "./text-base-common";
@ -20,15 +19,15 @@ function getCapitalizedString(str: string): string {
return newWords.join(" "); return newWords.join(" ");
} }
function formatString(text: string, textTransform: string): string { function formatString(text: string, textTransform: "none" | "capitalize" | "uppercase" | "lowercase"): string {
switch (textTransform) { switch (textTransform) {
case TextTransform.uppercase: case "uppercase":
return text.toUpperCase(); return text.toUpperCase();
case TextTransform.lowercase: case "lowercase":
return text.toLowerCase(); return text.toLowerCase();
case TextTransform.capitalize: case "capitalize":
return getCapitalizedString(text); return getCapitalizedString(text);
default: default:
@ -38,7 +37,7 @@ function formatString(text: string, textTransform: string): string {
@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: string) { constructor(public originalText: string, public formattedText: FormattedString, public textTransform: "none" | "capitalize" | "uppercase" | "lowercase") {
super(); super();
return global.__native(this); return global.__native(this);
} }
@ -84,8 +83,11 @@ export class TextBase extends TextBaseCommon {
return this.nativeView.getText(); return this.nativeView.getText();
} }
set [textProperty.native](value: string) { set [textProperty.native](value: string) {
let newValue = toUIString(value); if (value === null || value === undefined) {
this.nativeView.setText(newValue); value = "";
}
this.nativeView.setText(value);
} }
get [formattedTextProperty.native](): FormattedString { get [formattedTextProperty.native](): FormattedString {
@ -99,28 +101,45 @@ export class TextBase extends TextBaseCommon {
// .getTextColors().getDefaultColor(); // .getTextColors().getDefaultColor();
return this.nativeView.getCurrentTextColor(); return this.nativeView.getCurrentTextColor();
} }
set [colorProperty.native](value: number) { set [colorProperty.native](value: number | Color) {
this.nativeView.setTextColor(value); let color = value instanceof Color ? value.android : value;
this.nativeView.setTextColor(color);
} }
get [fontIntenal.native](): number { get [fontInternalProperty.native](): { typeface: android.graphics.Typeface, fontSize: number } {
return this.nativeView.getCurrentTextColor(); let textView = this.nativeView;
return {
typeface: textView.getTypeface(),
fontSize: textView.getTextSize()
};
} }
set [fontIntenal.native](value: number) { set [fontInternalProperty.native](value: Font | { typeface: android.graphics.Typeface, fontSize: number }) {
this.nativeView.setTextColor(value); let textView = this.nativeView;
let typeface: android.graphics.Typeface;
let fontSize: number;
if (value instanceof Font) {
typeface = value.getAndroidTypeface();
textView.setTextSize(value.fontSize);
} else {
typeface = value.typeface;
textView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.fontSize);
}
textView.setTypeface(typeface);
} }
get [textAlignmentProperty.native](): string { get [textAlignmentProperty.native](): string {
let textGravity = this.nativeView.getGravity() & android.view.View.TEXT_ALIGNMENT_GRAVITY; let textGravity = this.nativeView.getGravity() & android.view.View.TEXT_ALIGNMENT_GRAVITY;
switch (textGravity) { switch (textGravity) {
case android.view.Gravity.LEFT: case android.view.Gravity.LEFT:
return TextAlignment.left; return "left";
case android.view.Gravity.CENTER_HORIZONTAL: case android.view.Gravity.CENTER_HORIZONTAL:
return TextAlignment.center; return "center";
case android.view.Gravity.RIGHT: case android.view.Gravity.RIGHT:
return TextAlignment.right; return "right";
default: default:
throw new Error("Invalid textGravity: " + textGravity); throw new Error("Invalid textGravity: " + textGravity);
@ -129,13 +148,13 @@ export class TextBase extends TextBaseCommon {
set [textAlignmentProperty.native](value: string) { set [textAlignmentProperty.native](value: string) {
let verticalGravity = this.nativeView.getGravity() & android.view.Gravity.VERTICAL_GRAVITY_MASK; let verticalGravity = this.nativeView.getGravity() & android.view.Gravity.VERTICAL_GRAVITY_MASK;
switch (value) { switch (value) {
case TextAlignment.left: case "left":
this.nativeView.setGravity(android.view.Gravity.LEFT | verticalGravity); this.nativeView.setGravity(android.view.Gravity.LEFT | verticalGravity);
break; break;
case TextAlignment.center: case "center":
this.nativeView.setGravity(android.view.Gravity.CENTER_HORIZONTAL | verticalGravity); this.nativeView.setGravity(android.view.Gravity.CENTER_HORIZONTAL | verticalGravity);
break; break;
case TextAlignment.right: case "right":
this.nativeView.setGravity(android.view.Gravity.RIGHT | verticalGravity); this.nativeView.setGravity(android.view.Gravity.RIGHT | verticalGravity);
break; break;
default: default:
@ -143,42 +162,43 @@ export class TextBase extends TextBaseCommon {
} }
} }
get [textDecorationProperty.native](): string { get [textDecorationProperty.native](): "none" | "underline" | "line-through" {
return TextDecoration.none; return "none";
} }
set [textDecorationProperty.native](value: string) { set [textDecorationProperty.native](value: "none" | "underline" | "line-through") {
let flags = 0; let flags = 0;
let values = (value + "").split(" "); let values = (value + "").split(" ");
if (values.indexOf(TextDecoration.underline) !== -1) { if (values.indexOf("underline") !== -1) {
flags = flags | android.graphics.Paint.UNDERLINE_TEXT_FLAG; flags = flags | android.graphics.Paint.UNDERLINE_TEXT_FLAG;
} }
if (values.indexOf(TextDecoration.lineThrough) !== -1) { if (values.indexOf("line-through") !== -1) {
flags = flags | android.graphics.Paint.STRIKE_THRU_TEXT_FLAG; flags = flags | android.graphics.Paint.STRIKE_THRU_TEXT_FLAG;
} }
if (values.indexOf(TextDecoration.none) === -1) { if (values.indexOf("none") === -1) {
this.nativeView.setPaintFlags(flags); this.nativeView.setPaintFlags(flags);
} else { } else {
this.nativeView.setPaintFlags(0); this.nativeView.setPaintFlags(0);
} }
} }
get [textTransformProperty.native](): string { get [textTransformProperty.native](): "none" | "capitalize" | "uppercase" | "lowercase" {
return TextTransform.none; return "none";
} }
set [textTransformProperty.native](value: string) { set [textTransformProperty.native](value: "none" | "capitalize" | "uppercase" | "lowercase") {
this._setFormattedTextPropertyToNative(this.formattedText); this._setFormattedTextPropertyToNative(this.formattedText);
} }
get [whiteSpaceProperty.native](): string { get [whiteSpaceProperty.native](): "normal" | "nowrap" {
return WhiteSpace.normal; return "normal";
} }
set [whiteSpaceProperty.native](value: string) { set [whiteSpaceProperty.native](value: "normal" | "nowrap") {
let nativeView = this.nativeView; let nativeView = this.nativeView;
nativeView.setSingleLine(value === WhiteSpace.nowrap); let nowrap = value === "nowrap";
nativeView.setEllipsize(value === WhiteSpace.nowrap ? android.text.TextUtils.TruncateAt.END : null); nativeView.setSingleLine(nowrap);
nativeView.setEllipsize(nowrap ? android.text.TextUtils.TruncateAt.END : null);
} }
get [letterSpacingProperty.native](): number { get [letterSpacingProperty.native](): number {

View File

@ -75,4 +75,6 @@
export const textTransformProperty: CssProperty<Style, "none" | "capitalize" | "uppercase" | "lowercase">; export const textTransformProperty: CssProperty<Style, "none" | "capitalize" | "uppercase" | "lowercase">;
export const whiteSpaceProperty: CssProperty<Style, "normal" | "nowrap">; export const whiteSpaceProperty: CssProperty<Style, "normal" | "nowrap">;
export const letterSpacingProperty: CssProperty<Style, number>; export const letterSpacingProperty: CssProperty<Style, number>;
export * from "ui/core/view";
} }

View File

@ -1,10 +1,8 @@
import { import {
TextBaseCommon, textProperty, formattedTextProperty, textAlignmentProperty, textDecorationProperty, TextBaseCommon, textProperty, formattedTextProperty, textAlignmentProperty, textDecorationProperty,
textTransformProperty, whiteSpaceProperty, letterSpacingProperty textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty
} from "./text-base-common"; } from "./text-base-common";
import { FormattedString } from "text/formatted-string"; import { FormattedString } from "text/formatted-string";
import { colorProperty, fontInternalProperty } from "ui/core/view";
import { toUIString, isNumber } from "utils/types";
import { Font } from "ui/styling/font"; import { Font } from "ui/styling/font";
import { Color } from "color"; import { Color } from "color";
@ -36,18 +34,18 @@ function updateFormattedStringTextDecoration(formattedText: FormattedString, dec
// TODO: Refactor this method so it doesn't modify FormattedString properties. // TODO: Refactor this method so it doesn't modify FormattedString properties.
// Instead it should create NSAttributedString and apply it to the nativeView. // Instead it should create NSAttributedString and apply it to the nativeView.
let textDecoration = decoration + ""; let textDecoration = decoration + "";
if (textDecoration.indexOf(TextDecoration.none) !== -1) { if (textDecoration.indexOf("none") !== -1) {
formattedText.underline = NSUnderlineStyle.StyleNone; formattedText.underline = NSUnderlineStyle.StyleNone;
formattedText.strikethrough = NSUnderlineStyle.StyleNone; formattedText.strikethrough = NSUnderlineStyle.StyleNone;
} }
else { else {
if (textDecoration.indexOf(TextDecoration.underline) !== -1) { if (textDecoration.indexOf("underline") !== -1) {
formattedText.underline = NSUnderlineStyle.StyleSingle; formattedText.underline = NSUnderlineStyle.StyleSingle;
} else { } else {
formattedText.underline = NSUnderlineStyle.StyleNone; formattedText.underline = NSUnderlineStyle.StyleNone;
} }
if (textDecoration.indexOf(TextDecoration.lineThrough) !== -1) { if (textDecoration.indexOf("line-through") !== -1) {
formattedText.strikethrough = NSUnderlineStyle.StyleSingle; formattedText.strikethrough = NSUnderlineStyle.StyleSingle;
} else { } else {
formattedText.strikethrough = NSUnderlineStyle.StyleNone; formattedText.strikethrough = NSUnderlineStyle.StyleNone;
@ -55,7 +53,7 @@ function updateFormattedStringTextDecoration(formattedText: FormattedString, dec
} }
} }
function updateFormattedStringTextTransformation(formattedText: FormattedString, transform: string): void { function updateFormattedStringTextTransformation(formattedText: FormattedString, transform: "none" | "capitalize" | "uppercase" | "lowercase"): void {
// TODO: Refactor this method so it doesn't modify Span properties. // TODO: Refactor this method so it doesn't modify Span properties.
// Instead it should create NSAttributedString and apply it to the nativeView. // Instead it should create NSAttributedString and apply it to the nativeView.
for (let i = 0, length = formattedText.spans.length; i < length; i++) { for (let i = 0, length = formattedText.spans.length; i < length; i++) {
@ -64,11 +62,11 @@ function updateFormattedStringTextTransformation(formattedText: FormattedString,
} }
} }
function setFormattedTextDecorationAndTransform(formattedText: FormattedString, nativeView: UITextField | UITextView | UILabel | UIButton, decoration: string, transform: string, letterSpacing: number) { function setFormattedTextDecorationAndTransform(formattedText: FormattedString, nativeView: UITextField | UITextView | UILabel | UIButton, decoration: string, transform: "none" | "capitalize" | "uppercase" | "lowercase", letterSpacing: number) {
updateFormattedStringTextDecoration(formattedText, decoration); updateFormattedStringTextDecoration(formattedText, decoration);
updateFormattedStringTextTransformation(formattedText, transform); updateFormattedStringTextTransformation(formattedText, transform);
if (isNumber(letterSpacing) && !isNaN(letterSpacing)) { if (typeof letterSpacing === "number" && !isNaN(letterSpacing)) {
if (nativeView instanceof UIButton) { if (nativeView instanceof UIButton) {
let attrText = NSMutableAttributedString.alloc().initWithAttributedString(nativeView.attributedTitleForState(UIControlState.Normal)); let attrText = NSMutableAttributedString.alloc().initWithAttributedString(nativeView.attributedTitleForState(UIControlState.Normal));
attrText.addAttributeValueRange(NSKernAttributeName, letterSpacing * nativeView.font.pointSize, { location: 0, length: attrText.length }); attrText.addAttributeValueRange(NSKernAttributeName, letterSpacing * nativeView.font.pointSize, { location: 0, length: attrText.length });
@ -81,17 +79,17 @@ function setFormattedTextDecorationAndTransform(formattedText: FormattedString,
} }
} }
function setTextDecorationAndTransform(text: string, nativeView: UITextField | UITextView | UILabel | UIButton, decoration: string, transform: string, letterSpacing: number, color: Color) { function setTextDecorationAndTransform(text: string, nativeView: UITextField | UITextView | UILabel | UIButton, decoration: string, transform: "none" | "capitalize" | "uppercase" | "lowercase", letterSpacing: number, color: Color) {
let hasLetterSpacing = isNumber(letterSpacing) && !isNaN(letterSpacing); let hasLetterSpacing = typeof letterSpacing === "number" && !isNaN(letterSpacing);
let decorationValues = decoration + ""; let decorationValues = decoration + "";
let dict = new Map<string, number>(); let dict = new Map<string, number>();
if (decorationValues.indexOf(TextDecoration.none) === -1) { if (decorationValues.indexOf("none") === -1) {
if (decorationValues.indexOf(TextDecoration.underline) !== -1) { if (decorationValues.indexOf("underline") !== -1) {
dict.set(NSUnderlineStyleAttributeName, NSUnderlineStyle.StyleSingle); dict.set(NSUnderlineStyleAttributeName, NSUnderlineStyle.StyleSingle);
} }
if (decorationValues.indexOf(TextDecoration.lineThrough) !== -1) { if (decorationValues.indexOf("line-through") !== -1) {
dict.set(NSStrikethroughStyleAttributeName, NSUnderlineStyle.StyleSingle); dict.set(NSStrikethroughStyleAttributeName, NSUnderlineStyle.StyleSingle);
} }
} }
@ -204,12 +202,12 @@ export class TextBase extends TextBaseCommon {
} }
} }
get [fontIntenal.native](): UIFont { get [fontInternalProperty.native](): UIFont {
let nativeView = this.nativeView; let nativeView = this.nativeView;
nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView; nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView;
return nativeView.font; return nativeView.font;
} }
set [fontIntenal.native](value: Font) { set [fontInternalProperty.native](value: Font) {
let nativeView = this.nativeView; let nativeView = this.nativeView;
nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView; nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView;
let font = value instanceof Font ? value.getUIFont(nativeView.font) : value; let font = value instanceof Font ? value.getUIFont(nativeView.font) : value;
@ -221,13 +219,13 @@ export class TextBase extends TextBaseCommon {
nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView; nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView;
switch (nativeView.textAlignment) { switch (nativeView.textAlignment) {
case NSTextAlignment.Left: case NSTextAlignment.Left:
return TextAlignment.left; return "left";
case NSTextAlignment.Center: case NSTextAlignment.Center:
return TextAlignment.center; return "center";
case NSTextAlignment.Right: case NSTextAlignment.Right:
return TextAlignment.right; return "right";
} }
} }
set [textAlignmentProperty.native](value: string) { set [textAlignmentProperty.native](value: string) {
@ -235,13 +233,13 @@ export class TextBase extends TextBaseCommon {
nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView; nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView;
// NOTE: if Button textAlignment is not enough - set also btn.contentHorizontalAlignment // NOTE: if Button textAlignment is not enough - set also btn.contentHorizontalAlignment
switch (value) { switch (value) {
case TextAlignment.left: case "left":
nativeView.textAlignment = NSTextAlignment.Left; nativeView.textAlignment = NSTextAlignment.Left;
break; break;
case TextAlignment.center: case "center":
nativeView.textAlignment = NSTextAlignment.Center; nativeView.textAlignment = NSTextAlignment.Center;
break; break;
case TextAlignment.right: case "right":
nativeView.textAlignment = NSTextAlignment.Right; nativeView.textAlignment = NSTextAlignment.Right;
break; break;
default: default:
@ -250,7 +248,7 @@ export class TextBase extends TextBaseCommon {
} }
get [textDecorationProperty.native](): string { get [textDecorationProperty.native](): string {
return TextDecoration.none; return "none";
} }
set [textDecorationProperty.native](value: string) { set [textDecorationProperty.native](value: string) {
if (this.formattedText) { if (this.formattedText) {
@ -261,9 +259,9 @@ export class TextBase extends TextBaseCommon {
} }
get [textTransformProperty.native](): string { get [textTransformProperty.native](): string {
return TextTransform.none; return "none";
} }
set [textTransformProperty.native](value: string) { set [textTransformProperty.native](value: "none" | "capitalize" | "uppercase" | "lowercase") {
if (this.formattedText) { if (this.formattedText) {
setFormattedTextDecorationAndTransform(this.formattedText, this.nativeView, this.style.textDecoration, value, this.style.letterSpacing); setFormattedTextDecorationAndTransform(this.formattedText, this.nativeView, this.style.textDecoration, value, this.style.letterSpacing);
} else { } else {

View File

@ -5,7 +5,7 @@ declare module "ui/text-field" {
import { Property } from "ui/core/properties"; import { Property } from "ui/core/properties";
import { EditableTextBase } from "ui/editable-text-base"; import { EditableTextBase } from "ui/editable-text-base";
export let secureProperty: Property<TextField, boolean>; export const secureProperty: Property<TextField, boolean>;
/** /**
* Represents an editable text field. * Represents an editable text field.

View File

@ -1,10 +1,4 @@
import { View } from "ui/core/view"; import { TextFieldBase, secureProperty, textProperty, hintProperty, colorProperty, placeholderColorProperty } from "./text-field-common";
import { TextFieldBase, secureProperty } from "./text-field-common";
import { hintProperty } from "ui/editable-text-base";
import { textProperty } from "ui/text-base";
import { UpdateTextTrigger } from "ui/enums";
import { colorProperty, placeholderColorProperty } from "ui/styling/style";
export * from "./text-field-common"; export * from "./text-field-common";
@ -33,7 +27,7 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
public textFieldDidEndEditing(textField: UITextField) { public textFieldDidEndEditing(textField: UITextField) {
let owner = this._owner.get(); let owner = this._owner.get();
if (owner) { if (owner) {
if (owner.updateTextTrigger === UpdateTextTrigger.focusLost) { if (owner.updateTextTrigger === "focusLost") {
owner.nativePropertyChanged(textProperty, textField.text); owner.nativePropertyChanged(textProperty, textField.text);
} }
@ -68,7 +62,7 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
public textFieldShouldChangeCharactersInRangeReplacementString(textField: UITextField, range: NSRange, replacementString: string): boolean { public textFieldShouldChangeCharactersInRangeReplacementString(textField: UITextField, range: NSRange, replacementString: string): boolean {
let owner = this._owner.get(); let owner = this._owner.get();
if (owner) { if (owner) {
if (owner.updateTextTrigger === UpdateTextTrigger.textChanged) { if (owner.updateTextTrigger === "textChanged") {
if (textField.secureTextEntry && this.firstEdit) { if (textField.secureTextEntry && this.firstEdit) {
owner.nativePropertyChanged(textProperty, replacementString); owner.nativePropertyChanged(textProperty, replacementString);
} }
@ -108,9 +102,10 @@ class UITextFieldImpl extends UITextField {
} }
let size = bounds.size; let size = bounds.size;
return CGRectMake(owner.borderLeftWidth + owner.style.paddingLeft, owner.borderTopWidth + owner.style.paddingTop, let style = owner.style;
size.width - (owner.borderLeftWidth + owner.style.paddingLeft + owner.style.paddingRight + owner.borderRightWidth), return CGRectMake(style.effectiveBorderLeftWidth + style.effectivePaddingLeft, style.effectiveBorderTopWidth + style.effectivePaddingTop,
size.height - (owner.borderTopWidth + owner.style.paddingTop + owner.style.paddingBottom + owner.borderBottomWidth) size.width - (style.effectiveBorderLeftWidth + style.effectivePaddingLeft + style.effectivePaddingRight + style.effectiveBorderRightWidth),
size.height - (style.effectiveBorderTopWidth + style.effectivePaddingTop + style.effectivePaddingBottom + style.effectiveBorderBottomWidth)
); );
} }

View File

@ -1,12 +1,11 @@
import { TextView as TextViewDefinition } from "ui/text-view"; import { TextView as TextViewDefinition } from "ui/text-view";
import { EditableTextBase, editableProperty, hintProperty } from "ui/editable-text-base";
import { textProperty } from "ui/text-base";
import { UpdateTextTrigger } from "ui/enums";
import { import {
colorProperty, borderTopWidthProperty, borderRightWidthProperty, EditableTextBase, editableProperty, hintProperty, textProperty, colorProperty,
borderBottomWidthProperty, borderLeftWidthProperty, nativePaddingsProperty borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty,
} from "ui/styling/style"; paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length
import * as utils from "utils/utils";
} from "ui/editable-text-base";
import { ios } from "utils/utils";
export * from "ui/editable-text-base"; export * from "ui/editable-text-base";
@ -33,7 +32,7 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
public textViewDidEndEditing(textView: UITextView) { public textViewDidEndEditing(textView: UITextView) {
let owner = this._owner.get(); let owner = this._owner.get();
if (owner) { if (owner) {
if (owner.updateTextTrigger === UpdateTextTrigger.focusLost) { if (owner.updateTextTrigger === "focusLost") {
owner.nativePropertyChangeded(textProperty, textView.text); owner.nativePropertyChangeded(textProperty, textView.text);
} }
@ -54,7 +53,7 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
public textViewDidChange(textView: UITextView) { public textViewDidChange(textView: UITextView) {
let owner = this._owner.get(); let owner = this._owner.get();
if (owner) { if (owner) {
if (owner.updateTextTrigger === UpdateTextTrigger.textChanged) { if (owner.updateTextTrigger === "textChanged") {
owner.nativePropertyChangeded(textProperty, textView.text); owner.nativePropertyChangeded(textProperty, textView.text);
} }
} }
@ -112,7 +111,7 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
public _showHint(hint: string) { public _showHint(hint: string) {
let nativeView = this.nativeView; let nativeView = this.nativeView;
nativeView.textColor = nativeView.textColor ? nativeView.textColor.colorWithAlphaComponent(0.22) : utils.ios.getter(UIColor, UIColor.blackColor).colorWithAlphaComponent(0.22); nativeView.textColor = nativeView.textColor ? nativeView.textColor.colorWithAlphaComponent(0.22) : ios.getter(UIColor, UIColor.blackColor).colorWithAlphaComponent(0.22);
nativeView.text = hint + ""; nativeView.text = hint + "";
this._isShowingHint = true; this._isShowingHint = true;
} }
@ -164,60 +163,107 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
} }
} }
get [borderTopWidthProperty.native](): number { get [borderTopWidthProperty.native](): Length {
return this.nativeView.textContainerInset.top; return {
value: this.nativeView.textContainerInset.top,
unit: "px"
};
} }
set [borderTopWidthProperty.native](value: number) { set [borderTopWidthProperty.native](value: Length) {
let inset = this.nativeView.textContainerInset; let inset = this.nativeView.textContainerInset;
let top = this.style.paddingTop + value; let style = this.style;
let top = style.effectivePaddingTop + style.effectiveBorderTopWidth;
this.nativeView.textContainerInset = { top: top, left: inset.left, bottom: inset.bottom, right: inset.right }; this.nativeView.textContainerInset = { top: top, left: inset.left, bottom: inset.bottom, right: inset.right };
} }
get [borderRightWidthProperty.native](): number {
return this.nativeView.textContainerInset.right; get [borderRightWidthProperty.native](): Length {
return {
value: this.nativeView.textContainerInset.right,
unit: "px"
};
} }
set [borderRightWidthProperty.native](value: number) { set [borderRightWidthProperty.native](value: Length) {
let inset = this.nativeView.textContainerInset; let inset = this.nativeView.textContainerInset;
let right = this.style.paddingRight + value; let style = this.style;
let right = style.effectivePaddingRight + style.effectiveBorderRightWidth;
this.nativeView.textContainerInset = { top: inset.top, left: inset.left, bottom: inset.bottom, right: right }; this.nativeView.textContainerInset = { top: inset.top, left: inset.left, bottom: inset.bottom, right: right };
} }
get [borderBottomWidthProperty.native](): number {
return this.nativeView.textContainerInset.bottom; get [borderBottomWidthProperty.native](): Length {
return {
value: this.nativeView.textContainerInset.bottom,
unit: "px"
};
} }
set [borderBottomWidthProperty.native](value: number) { set [borderBottomWidthProperty.native](value: Length) {
let inset = this.nativeView.textContainerInset; let inset = this.nativeView.textContainerInset;
let bottom = this.style.paddingBottom + value; let style = this.style;
let bottom = style.effectivePaddingBottom + style.effectiveBorderBottomWidth;
this.nativeView.textContainerInset = { top: inset.top, left: inset.left, bottom: bottom, right: inset.right }; this.nativeView.textContainerInset = { top: inset.top, left: inset.left, bottom: bottom, right: inset.right };
} }
get [borderLeftWidthProperty.native](): number {
return this.nativeView.textContainerInset.left; get [borderLeftWidthProperty.native](): Length {
return {
value: this.nativeView.textContainerInset.left,
unit: "px"
};
} }
set [borderLeftWidthProperty.native](value: number) { set [borderLeftWidthProperty.native](value: Length) {
let inset = this.nativeView.textContainerInset; let inset = this.nativeView.textContainerInset;
let left = this.style.paddingLeft + value; let style = this.style;
let left = style.effectivePaddingLeft + style.effectiveBorderLeftWidth;
this.nativeView.textContainerInset = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right }; this.nativeView.textContainerInset = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right };
} }
get [nativePaddingsProperty.native](): UIEdgeInsets { get [paddingTopProperty.native](): Length {
return this.nativeView.textContainerInset; return {
value: this.nativeView.textContainerInset.top,
unit: "px"
};
} }
set [nativePaddingsProperty.native](value: UIEdgeInsets) { set [paddingTopProperty.native](value: Length) {
let inset: UIEdgeInsets; let inset = this.nativeView.textContainerInset;
if (!value) { let style = this.style;
inset = { let top = style.effectivePaddingTop + style.effectiveBorderTopWidth;
top: this.style.borderTopWidth, this.nativeView.textContainerInset = { top: top, left: inset.left, bottom: inset.bottom, right: inset.right };
left: this.style.borderLeftWidth,
bottom: this.style.borderBottomWidth,
right: this.style.borderRightWidth
};
} else {
inset = {
top: this.style.borderTopWidth + value.top,
left: this.style.borderLeftWidth + value.left,
bottom: this.style.borderBottomWidth + value.bottom,
right: this.style.borderRightWidth + value.right
};
} }
this.nativeView.textContainerInset = inset; get [paddingRightProperty.native](): Length {
return {
value: this.nativeView.textContainerInset.right,
unit: "px"
};
}
set [paddingRightProperty.native](value: Length) {
let inset = this.nativeView.textContainerInset;
let style = this.style;
let right = style.effectivePaddingRight + style.effectiveBorderRightWidth;
this.nativeView.textContainerInset = { top: inset.top, left: inset.left, bottom: inset.bottom, right: right };
}
get [paddingBottomProperty.native](): Length {
return {
value: this.nativeView.textContainerInset.bottom,
unit: "px"
};
}
set [paddingBottomProperty.native](value: Length) {
let inset = this.nativeView.textContainerInset;
let style = this.style;
let bottom = style.effectivePaddingBottom + style.effectiveBorderBottomWidth;
this.nativeView.textContainerInset = { top: inset.top, left: inset.left, bottom: bottom, right: inset.right };
}
get [paddingLeftProperty.native](): Length {
return {
value: this.nativeView.textContainerInset.left,
unit: "px"
};
}
set [paddingLeftProperty.native](value: Length) {
let inset = this.nativeView.textContainerInset;
let style = this.style;
let left = style.effectivePaddingLeft + style.effectiveBorderLeftWidth;
this.nativeView.textContainerInset = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right };
} }
} }

View File

@ -1,8 +1,10 @@
import { TimePicker as TimePickerDefinition } from "ui/time-picker"; import { TimePicker as TimePickerDefinition } from "ui/time-picker";
import { View } from "ui/core/view"; import { View } from "ui/core/view";
import { Property } from "ui/core/properties"; import { Property } from "ui/core/properties";
import { isNumber, isDefined } from "utils/types";
ADD parseFloat as converter to all <number> properties!!!!!!!!!
export * from "ui/core/view";
interface Time { interface Time {
hour: number; hour: number;
minute: number; minute: number;
@ -37,15 +39,15 @@ function isValidTime(picker: TimePickerDefinition): boolean {
} }
function isHourValid(value: number): boolean { function isHourValid(value: number): boolean {
return isNumber(value) && value >= 0 && value <= 23; return typeof value === "number" && value >= 0 && value <= 23;
} }
function isMinuteValid(value: number): boolean { function isMinuteValid(value: number): boolean {
return isNumber(value) && value >= 0 && value <= 59; return typeof value === "number" && value >= 0 && value <= 59;
} }
function isMinuteIntervalValid(value: number): boolean { function isMinuteIntervalValid(value: number): boolean {
return isNumber(value) && value >= 1 && value <= 30 && 60 % value === 0; return typeof value === "number" && value >= 1 && value <= 30 && 60 % value === 0;
} }
function getMinutes(hour: number): number { function getMinutes(hour: number): number {

View File

@ -1,9 +1,10 @@
import { TimePickerBase, timeProperty, minuteIntervalProperty, import { TimePickerBase, timeProperty, minuteIntervalProperty,
minuteProperty, minMinuteProperty, maxMinuteProperty, minuteProperty, minMinuteProperty, maxMinuteProperty,
hourProperty, minHourProperty, maxHourProperty } from "./time-picker-common"; hourProperty, minHourProperty, maxHourProperty, colorProperty } from "./time-picker-common";
import { colorProperty } from "ui/styling/style";
import * as utils from "utils/utils"; import { ios } from "utils/utils";
import getter = utils.ios.getter; import getter = ios.getter;
export * from "./time-picker-common"; export * from "./time-picker-common";
function getDate(hour: number, minute: number): Date { function getDate(hour: number, minute: number): Date {