Fix setting text property to number. (#3449)

Fix setting JS property from native.
This commit is contained in:
Hristo Hristov
2017-01-09 18:13:31 +02:00
committed by GitHub
parent e3acdcbc78
commit 309ea148e1
23 changed files with 156 additions and 153 deletions

View File

@@ -275,4 +275,4 @@ export function fromObjectRecursive(source: any): Observable {
let observable = new Observable();
addPropertiesFromObject(observable, source, true);
return observable;
}
}

View File

@@ -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<T, U> {
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<T, U> extends PropertyOptions<T, U> {
readonly coerceValue: (t: T, u: U) => U;
}
export interface ShorthandPropertyOptions<P> {
name: string;
cssName: string;
converter(this: void, value: string | P): [CssProperty<any, any>, any][];
getter(this: Style): string | P;
}
export interface CssPropertyOptions<T extends Style, U> extends PropertyOptions<T, U> {
cssName: string;
}
export class Property<T extends ViewBase, U> implements PropertyDescriptor {
export class Property<T extends ViewBase, U> implements PropertyDescriptor, definitions.Property<T, U> {
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<T, U>) {
constructor(options: definitions.PropertyOptions<T, U>) {
const name = options.name;
this.name = name;
@@ -85,12 +63,12 @@ export class Property<T extends ViewBase, U> 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<T extends ViewBase, U> 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<T extends ViewBase, U> implements PropertyDescriptor {
}
}
export class CoercibleProperty<T extends ViewBase, U> implements PropertyDescriptor {
export class CoercibleProperty<T extends ViewBase, U> implements PropertyDescriptor, definitions.CoercibleProperty<T, U> {
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<T extends ViewBase, U> implements PropertyDescrip
public readonly coerce: (target: T) => void;
constructor(options: CoerciblePropertyOptions<T, U>) {
constructor(options: definitions.CoerciblePropertyOptions<T, U>) {
const name = options.name;
this.name = name;
@@ -272,6 +275,31 @@ export class CoercibleProperty<T extends ViewBase, U> 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<T extends ViewBase, U> implements PropertyDescrip
}
}
export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> {
export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> implements definitions.InheritedProperty<T, U> {
public readonly sourceKey: symbol;
public readonly setInheritedValue: (value: U) => void;
constructor(options: PropertyOptions<T, U>) {
constructor(options: definitions.PropertyOptions<T, U>) {
super(options);
const name = options.name;
const key = this.key;
@@ -369,7 +397,7 @@ export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> {
}
}
export class CssProperty<T extends Style, U> {
export class CssProperty<T extends Style, U> implements definitions.CssProperty<T, U> {
private registered: boolean;
public readonly name: string;
@@ -384,7 +412,7 @@ export class CssProperty<T extends Style, U> {
public readonly defaultValueKey: symbol;
public readonly defaultValue: U;
constructor(options: CssPropertyOptions<T, U>) {
constructor(options: definitions.CssPropertyOptions<T, U>) {
const name = options.name;
this.name = name;
@@ -559,10 +587,10 @@ export class CssProperty<T extends Style, U> {
}
}
export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U> {
export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U> implements definitions.InheritedCssProperty<T,U> {
public setInheritedValue: (value: U) => void;
constructor(options: CssPropertyOptions<T, U>) {
constructor(options: definitions.CssPropertyOptions<T, U>) {
super(options);
const name = options.name;
@@ -684,7 +712,7 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
}
}
export class ShorthandProperty<T extends Style, P> {
export class ShorthandProperty<T extends Style, P> implements definitions.ShorthandProperty<T, P> {
private registered: boolean;
public readonly key: symbol;
@@ -697,7 +725,7 @@ export class ShorthandProperty<T extends Style, P> {
public readonly native: symbol;
public readonly sourceKey: symbol;
constructor(options: ShorthandPropertyOptions<P>) {
constructor(options: definitions.ShorthandPropertyOptions<P>) {
const name = options.name;
this.name = name;
@@ -712,7 +740,7 @@ export class ShorthandProperty<T extends Style, P> {
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;

View File

@@ -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<ViewBase, any>, 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 {
//
}

View File

@@ -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<any, any>, newValue: any): void;
isLayoutRequired: boolean;
_gestureObservers: any;
// _isInheritedChange(): boolean;
_updateLayout(): void;

View File

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

View File

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

View File

@@ -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<T extends ViewBase, U> implements TypedPropertyDescriptor<U> {
@@ -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<T extends ViewBase, U> extends Property<T, U> {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -17,14 +17,14 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
private firstEdit: boolean;
public static initWithOwner(owner: WeakRef<TextField>): UITextFieldDelegateImpl {
let delegate = <UITextFieldDelegateImpl>UITextFieldDelegateImpl.new();
const delegate = <UITextFieldDelegateImpl>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<TextField>;
public static initWithOwner(owner: WeakRef<TextField>): UITextFieldImpl {
let handler = <UITextFieldImpl>UITextFieldImpl.new();
const handler = <UITextFieldImpl>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)

View File

@@ -16,25 +16,25 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
private _owner: WeakRef<TextView>;
public static initWithOwner(owner: WeakRef<TextView>): UITextViewDelegateImpl {
let impl = <UITextViewDelegateImpl>UITextViewDelegateImpl.new();
const impl = <UITextViewDelegateImpl>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;
}

View File

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

View File

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