From 309ea148e1235d02ef6044d8ddf9ca0a879ea6de Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Mon, 9 Jan 2017 18:13:31 +0200 Subject: [PATCH] Fix setting text property to number. (#3449) Fix setting JS property from native. --- .../data/observable/observable.ts | 2 +- tns-core-modules/ui/core/properties.ts | 108 +++++++++++------- tns-core-modules/ui/core/view-base.ts | 14 --- tns-core-modules/ui/core/view.d.ts | 6 - .../ui/date-picker/date-picker.android.ts | 8 +- .../ui/date-picker/date-picker.ios.ts | 8 +- tns-core-modules/ui/definitions.d.ts | 2 + .../editable-text-base.android.ts | 13 +-- .../ui/list-picker/list-picker.android.ts | 4 +- .../ui/list-picker/list-picker.ios.ts | 2 +- .../ui/search-bar/search-bar.android.ts | 8 +- .../ui/search-bar/search-bar.ios.ts | 27 +++-- tns-core-modules/ui/slider/slider.android.ts | 2 +- tns-core-modules/ui/slider/slider.ios.ts | 2 +- tns-core-modules/ui/switch/switch.android.ts | 2 +- tns-core-modules/ui/switch/switch.ios.ts | 2 +- .../ui/text-base/text-base-common.ts | 2 +- .../ui/text-base/text-base.android.ts | 7 +- .../ui/text-base/text-base.ios.ts | 2 +- .../ui/text-field/text-field.ios.ts | 29 ++--- .../ui/text-view/text-view.ios.ts | 51 ++++----- .../ui/time-picker/time-picker.android.ts | 2 +- .../ui/time-picker/time-picker.ios.ts | 6 +- 23 files changed, 156 insertions(+), 153 deletions(-) diff --git a/tns-core-modules/data/observable/observable.ts b/tns-core-modules/data/observable/observable.ts index c10deec86..1cae395fc 100644 --- a/tns-core-modules/data/observable/observable.ts +++ b/tns-core-modules/data/observable/observable.ts @@ -275,4 +275,4 @@ export function fromObjectRecursive(source: any): Observable { let observable = new Observable(); addPropertiesFromObject(observable, source, true); return observable; -} +} \ No newline at end of file diff --git a/tns-core-modules/ui/core/properties.ts b/tns-core-modules/ui/core/properties.ts index 1c81ac8bd..f877bb71d 100644 --- a/tns-core-modules/ui/core/properties.ts +++ b/tns-core-modules/ui/core/properties.ts @@ -2,6 +2,7 @@ import { unsetValue } from "ui/core/dependency-observable"; import { WrappedValue } from "data/observable"; import { ViewBase } from "./view-base"; import { Style } from "ui/styling/style"; +import * as definitions from "ui/core/view-base"; export { unsetValue, Style }; @@ -31,44 +32,21 @@ const enum ValueSource { Local = 3 } -export interface PropertyOptions { - name: string; - defaultValue?: U; - affectsLayout?: boolean; - equalityComparer?(this: void, x: U, y: U): boolean; - valueChanged?(this: void, target: T, oldValue: U, newValue: U): void; - valueConverter?(this: void, value: string): U; -} - -export interface CoerciblePropertyOptions extends PropertyOptions { - readonly coerceValue: (t: T, u: U) => U; -} - -export interface ShorthandPropertyOptions

{ - name: string; - cssName: string; - converter(this: void, value: string | P): [CssProperty, any][]; - getter(this: Style): string | P; -} - -export interface CssPropertyOptions extends PropertyOptions { - cssName: string; -} - -export class Property implements PropertyDescriptor { +export class Property implements PropertyDescriptor, definitions.Property { private registered: boolean; private readonly name: string; public readonly key: symbol; public readonly native: symbol; public readonly defaultValueKey: symbol; public readonly defaultValue: U; + public readonly nativeValueChange: (owner: T, value: U) => void; public get: () => U; public set: (value: U) => void; public enumerable: boolean = true; public configurable: boolean = true; - constructor(options: PropertyOptions) { + constructor(options: definitions.PropertyOptions) { const name = options.name; this.name = name; @@ -85,12 +63,12 @@ export class Property implements PropertyDescriptor { this.defaultValue = defaultValue; const eventName = name + "Change"; - const affectsLayout: boolean = options.affectsLayout; const equalityComparer = options.equalityComparer; + const affectsLayout: boolean = options.affectsLayout; const valueChanged = options.valueChanged; const valueConverter = options.valueConverter; - this.set = function (this: T, value: any): void { + this.set = function (this: T, value: U): void { const reset = value === unsetValue; let unboxedValue: U; let wrapped: boolean; @@ -146,10 +124,34 @@ export class Property implements PropertyDescriptor { } } - this.get = function (): U { + this.get = function (this: T): U { return key in this ? this[key] : defaultValue; } + this.nativeValueChange = function (owner: T, value: U): void { + const currentValue = key in owner ? owner[key] : defaultValue; + const changed = equalityComparer ? !equalityComparer(currentValue, value) : currentValue !== value; + if (changed) { + owner[key] = value; + if (valueChanged) { + valueChanged(owner, currentValue, value); + } + + if (owner.hasListeners(eventName)) { + owner.notify({ + eventName: eventName, + propertyName: name, + object: owner, + value: value + }); + } + + if (affectsLayout) { + owner.requestLayout(); + } + } + } + symbolPropertyMap[key] = this; } @@ -162,13 +164,14 @@ export class Property implements PropertyDescriptor { } } -export class CoercibleProperty implements PropertyDescriptor { +export class CoercibleProperty implements PropertyDescriptor, definitions.CoercibleProperty { private registered: boolean; private readonly name: string; public readonly key: symbol; public readonly native: symbol; public readonly defaultValueKey: symbol; public readonly defaultValue: U; + public readonly nativeValueChange: (owner: T, value: U) => void; public readonly get: () => U; public readonly set: (value: U) => void; @@ -177,7 +180,7 @@ export class CoercibleProperty implements PropertyDescrip public readonly coerce: (target: T) => void; - constructor(options: CoerciblePropertyOptions) { + constructor(options: definitions.CoerciblePropertyOptions) { const name = options.name; this.name = name; @@ -272,6 +275,31 @@ export class CoercibleProperty implements PropertyDescrip return key in this ? this[key] : defaultValue; } + this.nativeValueChange = function (owner: T, value: U): void { + const currentValue = key in owner ? owner[key] : defaultValue; + const changed = equalityComparer ? !equalityComparer(currentValue, value) : currentValue !== value; + if (changed) { + owner[key] = value; + owner[coerceKey] = value; + if (valueChanged) { + valueChanged(owner, currentValue, value); + } + + if (owner.hasListeners(eventName)) { + owner.notify({ + eventName: eventName, + propertyName: name, + object: owner, + value: value + }); + } + + if (affectsLayout) { + owner.requestLayout(); + } + } + } + symbolPropertyMap[key] = this; } @@ -284,11 +312,11 @@ export class CoercibleProperty implements PropertyDescrip } } -export class InheritedProperty extends Property { +export class InheritedProperty extends Property implements definitions.InheritedProperty { public readonly sourceKey: symbol; public readonly setInheritedValue: (value: U) => void; - constructor(options: PropertyOptions) { + constructor(options: definitions.PropertyOptions) { super(options); const name = options.name; const key = this.key; @@ -369,7 +397,7 @@ export class InheritedProperty extends Property { } } -export class CssProperty { +export class CssProperty implements definitions.CssProperty { private registered: boolean; public readonly name: string; @@ -384,7 +412,7 @@ export class CssProperty { public readonly defaultValueKey: symbol; public readonly defaultValue: U; - constructor(options: CssPropertyOptions) { + constructor(options: definitions.CssPropertyOptions) { const name = options.name; this.name = name; @@ -559,10 +587,10 @@ export class CssProperty { } } -export class InheritedCssProperty extends CssProperty { +export class InheritedCssProperty extends CssProperty implements definitions.InheritedCssProperty { public setInheritedValue: (value: U) => void; - constructor(options: CssPropertyOptions) { + constructor(options: definitions.CssPropertyOptions) { super(options); const name = options.name; @@ -684,7 +712,7 @@ export class InheritedCssProperty extends CssProperty } } -export class ShorthandProperty { +export class ShorthandProperty implements definitions.ShorthandProperty { private registered: boolean; public readonly key: symbol; @@ -697,7 +725,7 @@ export class ShorthandProperty { public readonly native: symbol; public readonly sourceKey: symbol; - constructor(options: ShorthandPropertyOptions

) { + constructor(options: definitions.ShorthandPropertyOptions

) { const name = options.name; this.name = name; @@ -712,7 +740,7 @@ export class ShorthandProperty { const converter = options.converter; - function setLocalValue(this: T, value: string| P): void { + function setLocalValue(this: T, value: string | P): void { this[sourceKey] = ValueSource.Local; if (this[key] !== value) { this[key] = value; diff --git a/tns-core-modules/ui/core/view-base.ts b/tns-core-modules/ui/core/view-base.ts index d65f0f30a..0576f0be9 100644 --- a/tns-core-modules/ui/core/view-base.ts +++ b/tns-core-modules/ui/core/view-base.ts @@ -374,20 +374,6 @@ export class ViewBase extends Observable implements ViewBaseDefinition { } } - // public _setCore(data: PropertyChangeData) { - // super._setCore(data); - // this._updateTwoWayBinding(data.propertyName, data.value); - // } - - public nativePropertyChanged(property: Property, newValue: any): void { - if (this._updatingJSPropertiesDict[property.native]) { - return; - } - this._updatingJSPropertiesDict[property.native] = true; - property.set.call(this, newValue); - delete this._updatingJSPropertiesDict[property.native]; - } - public requestLayout(): void { // } diff --git a/tns-core-modules/ui/core/view.d.ts b/tns-core-modules/ui/core/view.d.ts index 911d4fd71..2a9db00ff 100644 --- a/tns-core-modules/ui/core/view.d.ts +++ b/tns-core-modules/ui/core/view.d.ts @@ -543,14 +543,8 @@ declare module "ui/core/view" { public eachChildView(callback: (view: View) => boolean): void; //@private - /** - * A property has changed on the native side directly - e.g. the user types in a TextField. - */ - public nativePropertyChanged(property: Property, newValue: any): void; - isLayoutRequired: boolean; _gestureObservers: any; - // _isInheritedChange(): boolean; _updateLayout(): void; diff --git a/tns-core-modules/ui/date-picker/date-picker.android.ts b/tns-core-modules/ui/date-picker/date-picker.android.ts index 6a70baaae..9e8343ebd 100644 --- a/tns-core-modules/ui/date-picker/date-picker.android.ts +++ b/tns-core-modules/ui/date-picker/date-picker.android.ts @@ -20,22 +20,22 @@ class DateChangedListener extends java.lang.Object implements android.widget.Dat let dateIsChanged = false; if (year !== owner.year) { - owner.nativePropertyChanged(yearProperty, year); + yearProperty.nativeValueChange(owner, year); dateIsChanged = true; } if ((month + 1) !== owner.month) { - owner.nativePropertyChanged(monthProperty, month + 1); + monthProperty.nativeValueChange(owner, month + 1); dateIsChanged = true; } if (day !== owner.day) { - owner.nativePropertyChanged(dayProperty, day); + dayProperty.nativeValueChange(owner, day); dateIsChanged = true; } if (dateIsChanged) { - owner.nativePropertyChanged(dateProperty, new Date(year, month, day)); + dateProperty.nativeValueChange(owner, new Date(year, month, day)); } } } diff --git a/tns-core-modules/ui/date-picker/date-picker.ios.ts b/tns-core-modules/ui/date-picker/date-picker.ios.ts index 43aa1e749..4cfe1902b 100644 --- a/tns-core-modules/ui/date-picker/date-picker.ios.ts +++ b/tns-core-modules/ui/date-picker/date-picker.ios.ts @@ -115,22 +115,22 @@ class UIDatePickerChangeHandlerImpl extends NSObject { let dateChanged = false; if (comps.year !== owner.year) { - owner.nativePropertyChanged(yearProperty, comps.year); + yearProperty.nativeValueChange(owner, comps.year); dateChanged = true; } if (comps.month !== owner.month) { - owner.nativePropertyChanged(monthProperty, comps.month); + monthProperty.nativeValueChange(owner, comps.month); dateChanged = true; } if (comps.day !== owner.day) { - owner.nativePropertyChanged(dayProperty, comps.day); + dayProperty.nativeValueChange(owner, comps.day); dateChanged = true; } if (dateChanged) { - owner.nativePropertyChanged(dateProperty, new Date(comps.year, comps.month - 1, comps.day)); + dateProperty.nativeValueChange(owner, new Date(comps.year, comps.month - 1, comps.day)); } } diff --git a/tns-core-modules/ui/definitions.d.ts b/tns-core-modules/ui/definitions.d.ts index fef79ae0c..18d8aa85a 100644 --- a/tns-core-modules/ui/definitions.d.ts +++ b/tns-core-modules/ui/definitions.d.ts @@ -209,6 +209,7 @@ declare module "ui/core/properties" { public readonly native: symbol; public readonly defaultValue: U; public register(cls: { prototype: T }): void; + public nativeValueChange(T, U): void; } export class CoercibleProperty implements TypedPropertyDescriptor { @@ -218,6 +219,7 @@ declare module "ui/core/properties" { public readonly defaultValue: U; public readonly coerce: (target: T) => void; public register(cls: { prototype: T }): void; + public nativeValueChange(T, U): void; } export class InheritedProperty extends Property { diff --git a/tns-core-modules/ui/editable-text-base/editable-text-base.android.ts b/tns-core-modules/ui/editable-text-base/editable-text-base.android.ts index 1fe01f106..6000d90b9 100644 --- a/tns-core-modules/ui/editable-text-base/editable-text-base.android.ts +++ b/tns-core-modules/ui/editable-text-base/editable-text-base.android.ts @@ -47,7 +47,7 @@ class TextWatcher extends java.lang.Object implements android.text.TextWatcher { owner._dirtyTextAccumulator = editable.toString(); break; case "textChanged": - owner.nativePropertyChanged(textProperty, editable.toString()); + textProperty.nativeValueChange(owner, editable.toString()); break; default: throw new Error("Invalid updateTextTrigger: " + owner.updateTextTrigger); @@ -81,7 +81,7 @@ class FocusChangeListener extends java.lang.Object implements android.view.View. } else { if (owner._dirtyTextAccumulator) { - owner.nativePropertyChanged(textProperty, owner._dirtyTextAccumulator); + textProperty.nativeValueChange(owner, owner._dirtyTextAccumulator); owner._dirtyTextAccumulator = undefined; } @@ -220,13 +220,8 @@ export abstract class EditableTextBase extends EditableTextBaseCommon { return this._android.getText(); } set [textProperty.native](value: string) { - let newValue; - if (value === null || value === void 0) { - newValue = ""; - } else { - newValue = value + ""; - } - this._android.setText(newValue, android.widget.TextView.BufferType.EDITABLE); + const text = (value === null || value === undefined) ? '' : value.toString(); + this._android.setText(text, android.widget.TextView.BufferType.EDITABLE); } get [keyboardTypeProperty.native](): "datetime" | "phone" | "number" | "url" | "email" | string { diff --git a/tns-core-modules/ui/list-picker/list-picker.android.ts b/tns-core-modules/ui/list-picker/list-picker.android.ts index f4388de3e..8a9aab01c 100644 --- a/tns-core-modules/ui/list-picker/list-picker.android.ts +++ b/tns-core-modules/ui/list-picker/list-picker.android.ts @@ -27,10 +27,10 @@ class ValueChangeListener extends java.lang.Object implements android.widget.Num return global.__native(this); } - onValueChange(picker: android.widget.NumberPicker, oldVal: number, newVal: number): void { + onValueChange(picker: android.widget.NumberPicker, oldValue: number, newValue: number): void { let owner = this.owner.get(); if (owner) { - owner.nativePropertyChanged(selectedIndexProperty, newVal); + selectedIndexProperty.nativeValueChange(owner, newValue); } } } diff --git a/tns-core-modules/ui/list-picker/list-picker.ios.ts b/tns-core-modules/ui/list-picker/list-picker.ios.ts index a49a9f80e..692d9999e 100644 --- a/tns-core-modules/ui/list-picker/list-picker.ios.ts +++ b/tns-core-modules/ui/list-picker/list-picker.ios.ts @@ -107,7 +107,7 @@ class ListPickerDelegateImpl extends NSObject implements UIPickerViewDelegate { public pickerViewDidSelectRowInComponent(pickerView: UIPickerView, row: number, component: number): void { let owner = this._owner.get(); if (owner) { - owner.nativePropertyChanged(selectedIndexProperty, row); + selectedIndexProperty.nativeValueChange(owner, row); } } } \ No newline at end of file diff --git a/tns-core-modules/ui/search-bar/search-bar.android.ts b/tns-core-modules/ui/search-bar/search-bar.android.ts index 1840332b9..a49cbde13 100644 --- a/tns-core-modules/ui/search-bar/search-bar.android.ts +++ b/tns-core-modules/ui/search-bar/search-bar.android.ts @@ -19,7 +19,7 @@ class QueryTextListener extends java.lang.Object implements android.widget.Searc onQueryTextChange(newText: string): boolean { let owner = this.owner.get(); if (owner) { - owner.nativePropertyChanged(textProperty, newText); + textProperty.nativeValueChange(owner, newText); // This code is needed since sometimes OnCloseListener is not called! if (newText === "" && this[SEARCHTEXT] !== newText) { @@ -163,13 +163,15 @@ export class SearchBar extends SearchBarBase { return ""; } set [textProperty.native](value: string) { - this._android.setQuery(value, false); + const text = (value === null || value === undefined) ? '' : value.toString(); + this._android.setQuery(text, false); } get [hintProperty.native](): string { return ""; } set [hintProperty.native](value: string) { - this._android.setQueryHint(value); + const text = (value === null || value === undefined) ? '' : value.toString(); + this._android.setQueryHint(text); } get [textFieldBackgroundColorProperty.native](): number { let textView = this._getTextView(); diff --git a/tns-core-modules/ui/search-bar/search-bar.ios.ts b/tns-core-modules/ui/search-bar/search-bar.ios.ts index 050e27d0e..dd91e9e80 100644 --- a/tns-core-modules/ui/search-bar/search-bar.ios.ts +++ b/tns-core-modules/ui/search-bar/search-bar.ios.ts @@ -22,7 +22,7 @@ class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate { return; } - owner.nativePropertyChanged(textProperty, searchText); + textProperty.nativeValueChange(owner, searchText); // This code is needed since sometimes searchBarCancelButtonClicked is not called! if (searchText === "") { @@ -143,19 +143,23 @@ export class SearchBar extends SearchBarBase { } get [textProperty.native](): string { - return ""; + return ''; } set [textProperty.native](value: string) { - this._ios.text = value; + const text = (value === null || value === undefined) ? '' : value.toString(); + this._ios.text = text; } + get [hintProperty.native](): string { - return ""; + return ''; } set [hintProperty.native](value: string) { - this._ios.placeholder = value; + const text = (value === null || value === undefined) ? '' : value.toString(); + this._ios.placeholder = text; } + get [textFieldBackgroundColorProperty.native](): UIColor { - let textField = this._textField; + const textField = this._textField; if (textField) { return textField.backgroundColor; } @@ -163,14 +167,15 @@ export class SearchBar extends SearchBarBase { return null; } set [textFieldBackgroundColorProperty.native](value: Color | UIColor) { - let color = value instanceof Color ? value.ios : value - let textField = this._textField; + const color = value instanceof Color ? value.ios : value + const textField = this._textField; if (textField) { textField.backgroundColor = color; } } + get [textFieldHintColorProperty.native](): UIColor { - let placeholderLabel = this._placeholderLabel; + const placeholderLabel = this._placeholderLabel; if (placeholderLabel) { return placeholderLabel.textColor; } @@ -178,8 +183,8 @@ export class SearchBar extends SearchBarBase { return null; } set [textFieldHintColorProperty.native](value: Color | UIColor) { - let color = value instanceof Color ? value.ios : value - let placeholderLabel = this._placeholderLabel; + const color = value instanceof Color ? value.ios : value + const placeholderLabel = this._placeholderLabel; if (placeholderLabel) { placeholderLabel.textColor = color; } diff --git a/tns-core-modules/ui/slider/slider.android.ts b/tns-core-modules/ui/slider/slider.android.ts index 90dad65af..4acca0323 100644 --- a/tns-core-modules/ui/slider/slider.android.ts +++ b/tns-core-modules/ui/slider/slider.android.ts @@ -18,7 +18,7 @@ class SeekBarChangeListener extends java.lang.Object implements android.widget.S if (owner) { if (!owner._supressNativeValue) { let newValue: number = seekBar.getProgress() + owner.minValue; - owner.nativePropertyChanged(valueProperty, newValue); + valueProperty.nativeValueChange(owner, newValue); } } } diff --git a/tns-core-modules/ui/slider/slider.ios.ts b/tns-core-modules/ui/slider/slider.ios.ts index 420382ae4..32af583f6 100644 --- a/tns-core-modules/ui/slider/slider.ios.ts +++ b/tns-core-modules/ui/slider/slider.ios.ts @@ -19,7 +19,7 @@ class SliderChangeHandlerImpl extends NSObject { public sliderValueChanged(sender: UISlider) { let owner = this._owner.get(); if (owner) { - owner.nativePropertyChanged(valueProperty, sender.value); + valueProperty.nativeValueChange(owner, sender.value); } } diff --git a/tns-core-modules/ui/switch/switch.android.ts b/tns-core-modules/ui/switch/switch.android.ts index 675e3db84..38c66e692 100644 --- a/tns-core-modules/ui/switch/switch.android.ts +++ b/tns-core-modules/ui/switch/switch.android.ts @@ -14,7 +14,7 @@ class CheckedChangeListener extends java.lang.Object implements android.widget.C onCheckedChanged(buttonView: android.widget.CompoundButton, isChecked: boolean): void { let owner = this.owner.get(); if (owner) { - owner.nativePropertyChanged(checkedProperty, isChecked); + checkedProperty.nativeValueChange(owner, isChecked); } } } diff --git a/tns-core-modules/ui/switch/switch.ios.ts b/tns-core-modules/ui/switch/switch.ios.ts index e86353635..91944c765 100644 --- a/tns-core-modules/ui/switch/switch.ios.ts +++ b/tns-core-modules/ui/switch/switch.ios.ts @@ -17,7 +17,7 @@ class SwitchChangeHandlerImpl extends NSObject { public valueChanged(sender: UISwitch) { let owner = this._owner.get(); if (owner) { - owner.nativePropertyChanged(checkedProperty, sender.on); + checkedProperty.nativeValueChange(owner, sender.on); } } diff --git a/tns-core-modules/ui/text-base/text-base-common.ts b/tns-core-modules/ui/text-base/text-base-common.ts index 0d5051cdc..8d8fb2e08 100644 --- a/tns-core-modules/ui/text-base/text-base-common.ts +++ b/tns-core-modules/ui/text-base/text-base-common.ts @@ -94,7 +94,7 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition, public onFormattedTextChanged(data: PropertyChangeData) { let value = data.value; this._setFormattedTextPropertyToNative(value); - this.nativePropertyChanged(textProperty, value.toString()); + textProperty.nativeValueChange(this, value.toString()); } public _addChildFromBuilder(name: string, value: any): void { diff --git a/tns-core-modules/ui/text-base/text-base.android.ts b/tns-core-modules/ui/text-base/text-base.android.ts index 020698ff0..76191471e 100644 --- a/tns-core-modules/ui/text-base/text-base.android.ts +++ b/tns-core-modules/ui/text-base/text-base.android.ts @@ -22,11 +22,8 @@ export class TextBase extends TextBaseCommon { return this._nativeView.getText(); } set [textProperty.native](value: string) { - if (value === null || value === undefined) { - value = ""; - } - - this._nativeView.setText(value); + const text = (value === null || value === undefined) ? '' : value.toString(); + this._nativeView.setText(text); } //FormattedText diff --git a/tns-core-modules/ui/text-base/text-base.ios.ts b/tns-core-modules/ui/text-base/text-base.ios.ts index 9b3de47f0..6b135dd3a 100644 --- a/tns-core-modules/ui/text-base/text-base.ios.ts +++ b/tns-core-modules/ui/text-base/text-base.ios.ts @@ -21,7 +21,7 @@ export class TextBase extends TextBaseCommon { } } set [textProperty.native](value: string) { - let newValue = (typeof value === "undefined") || (value === null) ? "" : value + ""; + let newValue = (value === undefined || value === null) ? '' : value.toString(); let nativeView = this.nativeView; if (nativeView instanceof UIButton) { nativeView.setTitleForState(newValue, UIControlState.Normal); diff --git a/tns-core-modules/ui/text-field/text-field.ios.ts b/tns-core-modules/ui/text-field/text-field.ios.ts index 549c5e03a..4c83f3ddb 100644 --- a/tns-core-modules/ui/text-field/text-field.ios.ts +++ b/tns-core-modules/ui/text-field/text-field.ios.ts @@ -17,14 +17,14 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate { private firstEdit: boolean; public static initWithOwner(owner: WeakRef): UITextFieldDelegateImpl { - let delegate = UITextFieldDelegateImpl.new(); + const delegate = UITextFieldDelegateImpl.new(); delegate._owner = owner; return delegate; } public textFieldShouldBeginEditing(textField: UITextField): boolean { this.firstEdit = true; - let owner = this._owner.get(); + const owner = this._owner.get(); if (owner) { return owner.editable; } @@ -33,10 +33,10 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate { } public textFieldDidEndEditing(textField: UITextField) { - let owner = this._owner.get(); + const owner = this._owner.get(); if (owner) { if (owner.updateTextTrigger === "focusLost") { - owner.nativePropertyChanged(textProperty, textField.text); + textProperty.nativeValueChange(owner, textField.text); } owner.dismissSoftInput(); @@ -49,9 +49,9 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate { public textFieldShouldClear(textField: UITextField) { this.firstEdit = false; - let owner = this._owner.get(); + const owner = this._owner.get(); if (owner) { - owner.nativePropertyChanged(textProperty, ""); + textProperty.nativeValueChange(owner, ''); } return true; @@ -59,25 +59,26 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate { public textFieldShouldReturn(textField: UITextField): boolean { // Called when the user presses the return button. - let owner = this._owner.get(); + const owner = this._owner.get(); if (owner) { owner.dismissSoftInput(); owner.notify({ eventName: TextField.returnPressEvent, object: owner }); } + return true; } public textFieldShouldChangeCharactersInRangeReplacementString(textField: UITextField, range: NSRange, replacementString: string): boolean { - let owner = this._owner.get(); + const owner = this._owner.get(); if (owner) { if (owner.updateTextTrigger === "textChanged") { if (textField.secureTextEntry && this.firstEdit) { - owner.nativePropertyChanged(textProperty, replacementString); + textProperty.nativeValueChange(owner, replacementString); } else { if (range.location <= textField.text.length) { - let newText = NSString.stringWithString(textField.text).stringByReplacingCharactersInRangeWithString(range, replacementString); - owner.nativePropertyChanged(textProperty, newText); + const newText = NSString.stringWithString(textField.text).stringByReplacingCharactersInRangeWithString(range, replacementString); + textProperty.nativeValueChange(owner, newText); } } } @@ -97,19 +98,19 @@ class UITextFieldImpl extends UITextField { private _owner: WeakRef; public static initWithOwner(owner: WeakRef): UITextFieldImpl { - let handler = UITextFieldImpl.new(); + const handler = UITextFieldImpl.new(); handler._owner = owner; return handler; } private _getTextRectForBounds(bounds: CGRect): CGRect { - let owner = this._owner ? this._owner.get() : null; + const owner = this._owner ? this._owner.get() : null; if (!owner) { return bounds; } - let size = bounds.size; + const size = bounds.size; return CGRectMake(owner.effectiveBorderLeftWidth + owner.effectivePaddingLeft, owner.effectiveBorderTopWidth + owner.effectivePaddingTop, size.width - (owner.effectiveBorderLeftWidth + owner.effectivePaddingLeft + owner.effectivePaddingRight + owner.effectiveBorderRightWidth), size.height - (owner.effectiveBorderTopWidth + owner.effectivePaddingTop + owner.effectivePaddingBottom + owner.effectiveBorderBottomWidth) diff --git a/tns-core-modules/ui/text-view/text-view.ios.ts b/tns-core-modules/ui/text-view/text-view.ios.ts index 32d09dff2..4487cf5d4 100644 --- a/tns-core-modules/ui/text-view/text-view.ios.ts +++ b/tns-core-modules/ui/text-view/text-view.ios.ts @@ -16,25 +16,25 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate { private _owner: WeakRef; public static initWithOwner(owner: WeakRef): UITextViewDelegateImpl { - let impl = UITextViewDelegateImpl.new(); + const impl = UITextViewDelegateImpl.new(); impl._owner = owner; return impl; } public textViewShouldBeginEditing(textView: UITextView): boolean { - let owner = this._owner.get(); + const owner = this._owner.get(); if (owner) { - owner._hideHint(); + owner.showText(); } return true; } public textViewDidEndEditing(textView: UITextView) { - let owner = this._owner.get(); + const owner = this._owner.get(); if (owner) { if (owner.updateTextTrigger === "focusLost") { - owner.nativePropertyChanged(textProperty, textView.text); + textProperty.nativeValueChange(owner, textView.text); } owner.dismissSoftInput(); @@ -44,24 +44,20 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate { owner.formattedText.createFormattedStringCore(); } - - // //RemoveThisDoubleCall - // owner.style._updateTextDecoration(); - // owner.style._updateTextTransform(); } } public textViewDidChange(textView: UITextView) { - let owner = this._owner.get(); + const owner = this._owner.get(); if (owner) { if (owner.updateTextTrigger === "textChanged") { - owner.nativePropertyChanged(textProperty, textView.text); + textProperty.nativeValueChange(owner, textView.text); } } } public textViewShouldChangeTextInRangeReplacementText(textView: UITextView, range: NSRange, replacementString: string): boolean { - let owner = this._owner.get(); + const owner = this._owner.get(); if (owner && owner.formattedText) { owner.formattedText._updateCharactersInRangeReplacementString(range.location, range.length, replacementString); } @@ -104,32 +100,29 @@ export class TextView extends EditableTextBase implements TextViewDefinition { } public _refreshHintState(hint: string, text: string) { - if (hint && !text) { - this._showHint(hint); - } - else { - this._hideHint(); + if (text !== null && text !== undefined && text !== '') { + this.showText(); + } else if (hint !== null && hint !== undefined && hint !== '') { + this.showHint(hint); + } else { + this._isShowingHint = false; + this.nativeView.text = ''; } } - public _showHint(hint: string) { - let nativeView = this.nativeView; + public showHint(hint: string) { + const nativeView = this.nativeView; nativeView.textColor = nativeView.textColor ? nativeView.textColor.colorWithAlphaComponent(0.22) : ios.getter(UIColor, UIColor.blackColor).colorWithAlphaComponent(0.22); - let hintAsString = hint + ""; - if (hint === null || hint === void 0) { - hintAsString = ""; - } + const hintAsString: string = (hint === null || hint === undefined) ? '' : hint.toString(); nativeView.text = hintAsString; this._isShowingHint = true; } - public _hideHint() { - let nativeView = this.nativeView; + public showText() { + const nativeView = this.nativeView; nativeView.textColor = this.color ? this.color.ios : null; - let textAsString = this.text + ""; - if (this.text === null || this.text === void 0) { - textAsString = ""; - } + const text = this.text; + const textAsString = (text === null || text === undefined) ? '' : text.toString(); nativeView.text = textAsString; this._isShowingHint = false; } diff --git a/tns-core-modules/ui/time-picker/time-picker.android.ts b/tns-core-modules/ui/time-picker/time-picker.android.ts index 98735186c..f0956f724 100644 --- a/tns-core-modules/ui/time-picker/time-picker.android.ts +++ b/tns-core-modules/ui/time-picker/time-picker.android.ts @@ -14,7 +14,7 @@ class TimeChangedListener extends java.lang.Object implements android.widget.Tim if (timePicker) { let validTime = getValidTime(timePicker, hour, minute); timePicker._setNativeValueSilently(validTime.hour, validTime.minute); - timePicker.nativePropertyChanged(timeProperty, new Date(0, 0, 0, validTime.hour, validTime.minute)); + timeProperty.nativeValueChange(timePicker, new Date(0, 0, 0, validTime.hour, validTime.minute)); } } } diff --git a/tns-core-modules/ui/time-picker/time-picker.ios.ts b/tns-core-modules/ui/time-picker/time-picker.ios.ts index 1b6370a28..555174641 100644 --- a/tns-core-modules/ui/time-picker/time-picker.ios.ts +++ b/tns-core-modules/ui/time-picker/time-picker.ios.ts @@ -127,17 +127,17 @@ class UITimePickerChangeHandlerImpl extends NSObject { let timeChanged = false; if (components.hour !== owner.hour) { - owner.nativePropertyChanged(hourProperty, components.hour); + hourProperty.nativeValueChange(owner, components.hour); timeChanged = true; } if (components.minute !== owner.minute) { - owner.nativePropertyChanged(minuteProperty, components.minute); + minuteProperty.nativeValueChange(owner, components.minute); timeChanged = true; } if (timeChanged) { - owner.nativePropertyChanged(timeProperty, new Date(0, 0, 0, components.hour, components.minute)); + timeProperty.nativeValueChange(owner, new Date(0, 0, 0, components.hour, components.minute)); } }