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();
}
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);
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);
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);
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);
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);
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);
export let autocorrectProperty = new Property<EditableTextBase, boolean>({ name: "autocorrect" });
export const autocorrectProperty = new Property<EditableTextBase, boolean>({ name: "autocorrect" });
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);

View File

@ -1,15 +1,17 @@
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 { Style } from "ui/styling/style";
import { Color } from "color";
export let keyboardTypeProperty: Property<EditableTextBase, string>;
export let returnKeyTypeProperty: Property<EditableTextBase, string>;
export let editableProperty: Property<EditableTextBase, boolean>;
export let updateTextTriggerProperty: Property<EditableTextBase, string>;
export let autocapitalizationTypeProperty: Property<EditableTextBase, string>;
export let autocorrectProperty: Property<EditableTextBase, boolean>;
export let hintProperty: Property<EditableTextBase, string>;
export const keyboardTypeProperty: Property<EditableTextBase, string>;
export const returnKeyTypeProperty: Property<EditableTextBase, string>;
export const editableProperty: Property<EditableTextBase, boolean>;
export const updateTextTriggerProperty: Property<EditableTextBase, string>;
export const autocapitalizationTypeProperty: Property<EditableTextBase, string>;
export const autocorrectProperty: Property<EditableTextBase, boolean>;
export const hintProperty: Property<EditableTextBase, string>;
export const placeholderColorProperty: CssProperty<Style, Color>;
/**
* 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).
*/
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).
@ -34,7 +36,7 @@
* Gets or sets the autocapitalization type. Possible values are contained in the [AutocapitalizationType enumeration](../enums/AutocapitalizationType/README.md).
*/
autocapitalizationType: "none" | "words" | "sentences" | "allCharacters";
/**
* Gets or sets whether the instance is editable.
*/
@ -55,4 +57,6 @@
*/
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);
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);
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) => {
switch (value) {
case "left":
@ -137,7 +137,7 @@ export let textAlignmentProperty = new InheritedCssProperty<Style, "left" | "cen
});
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) => {
let values = (value + "").split(" ");
@ -150,7 +150,7 @@ export let textDecorationProperty = new CssProperty<Style, "none" | "underline"
});
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) => {
switch (value) {
case "none":
@ -166,7 +166,7 @@ export let textTransformProperty = new CssProperty<Style, "none" | "capitalize"
});
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") => {
switch (value) {
case "normal":
@ -179,5 +179,5 @@ export let whiteSpaceProperty = new CssProperty<Style, "normal" | "nowrap">({
});
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);

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,4 @@
import { View } from "ui/core/view";
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";
import { TextFieldBase, secureProperty, textProperty, hintProperty, colorProperty, placeholderColorProperty } from "./text-field-common";
export * from "./text-field-common";
@ -33,7 +27,7 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
public textFieldDidEndEditing(textField: UITextField) {
let owner = this._owner.get();
if (owner) {
if (owner.updateTextTrigger === UpdateTextTrigger.focusLost) {
if (owner.updateTextTrigger === "focusLost") {
owner.nativePropertyChanged(textProperty, textField.text);
}
@ -68,7 +62,7 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
public textFieldShouldChangeCharactersInRangeReplacementString(textField: UITextField, range: NSRange, replacementString: string): boolean {
let owner = this._owner.get();
if (owner) {
if (owner.updateTextTrigger === UpdateTextTrigger.textChanged) {
if (owner.updateTextTrigger === "textChanged") {
if (textField.secureTextEntry && this.firstEdit) {
owner.nativePropertyChanged(textProperty, replacementString);
}
@ -108,9 +102,10 @@ class UITextFieldImpl extends UITextField {
}
let size = bounds.size;
return CGRectMake(owner.borderLeftWidth + owner.style.paddingLeft, owner.borderTopWidth + owner.style.paddingTop,
size.width - (owner.borderLeftWidth + owner.style.paddingLeft + owner.style.paddingRight + owner.borderRightWidth),
size.height - (owner.borderTopWidth + owner.style.paddingTop + owner.style.paddingBottom + owner.borderBottomWidth)
let style = owner.style;
return CGRectMake(style.effectiveBorderLeftWidth + style.effectivePaddingLeft, style.effectiveBorderTopWidth + style.effectivePaddingTop,
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 { EditableTextBase, editableProperty, hintProperty } from "ui/editable-text-base";
import { textProperty } from "ui/text-base";
import { UpdateTextTrigger } from "ui/enums";
import {
colorProperty, borderTopWidthProperty, borderRightWidthProperty,
borderBottomWidthProperty, borderLeftWidthProperty, nativePaddingsProperty
} from "ui/styling/style";
import * as utils from "utils/utils";
EditableTextBase, editableProperty, hintProperty, textProperty, colorProperty,
borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty,
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length
} from "ui/editable-text-base";
import { ios } from "utils/utils";
export * from "ui/editable-text-base";
@ -33,7 +32,7 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
public textViewDidEndEditing(textView: UITextView) {
let owner = this._owner.get();
if (owner) {
if (owner.updateTextTrigger === UpdateTextTrigger.focusLost) {
if (owner.updateTextTrigger === "focusLost") {
owner.nativePropertyChangeded(textProperty, textView.text);
}
@ -54,7 +53,7 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
public textViewDidChange(textView: UITextView) {
let owner = this._owner.get();
if (owner) {
if (owner.updateTextTrigger === UpdateTextTrigger.textChanged) {
if (owner.updateTextTrigger === "textChanged") {
owner.nativePropertyChangeded(textProperty, textView.text);
}
}
@ -112,7 +111,7 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
public _showHint(hint: string) {
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 + "";
this._isShowingHint = true;
}
@ -164,60 +163,107 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
}
}
get [borderTopWidthProperty.native](): number {
return this.nativeView.textContainerInset.top;
get [borderTopWidthProperty.native](): Length {
return {
value: this.nativeView.textContainerInset.top,
unit: "px"
};
}
set [borderTopWidthProperty.native](value: number) {
set [borderTopWidthProperty.native](value: Length) {
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 };
}
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 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 };
}
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 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 };
}
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 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 };
}
get [nativePaddingsProperty.native](): UIEdgeInsets {
return this.nativeView.textContainerInset;
get [paddingTopProperty.native](): Length {
return {
value: this.nativeView.textContainerInset.top,
unit: "px"
};
}
set [paddingTopProperty.native](value: Length) {
let inset = this.nativeView.textContainerInset;
let style = this.style;
let top = style.effectivePaddingTop + style.effectiveBorderTopWidth;
this.nativeView.textContainerInset = { top: top, left: inset.left, bottom: inset.bottom, right: inset.right };
}
set [nativePaddingsProperty.native](value: UIEdgeInsets) {
let inset: UIEdgeInsets;
if (!value) {
inset = {
top: this.style.borderTopWidth,
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 { View } from "ui/core/view";
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 {
hour: number;
minute: number;
@ -37,15 +39,15 @@ function isValidTime(picker: TimePickerDefinition): 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 {
return isNumber(value) && value >= 0 && value <= 59;
return typeof value === "number" && value >= 0 && value <= 59;
}
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 {

View File

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