From 7cd8e7ef54e7db66fb24d847a51ad3741dd4d04f Mon Sep 17 00:00:00 2001 From: Shiva Prasad Date: Wed, 21 Mar 2018 16:07:30 +0530 Subject: [PATCH] fix(text): Allow -1 to be a valid binding value for text views (#5563) * fix(android/text ios/text): allow -1 to be a valid binding value Instead of using -1 as special value, use Symbol(-1) so that it can't be reset accidentally Closes issue #5559 * renamed the symbol --- .../ui/editable-text-base/editable-text-base-common.ts | 2 +- .../editable-text-base/editable-text-base.android.ts | 10 +++++----- tns-core-modules/ui/text-base/text-base-common.ts | 2 ++ tns-core-modules/ui/text-base/text-base.android.ts | 10 +++++----- tns-core-modules/ui/text-base/text-base.d.ts | 2 ++ tns-core-modules/ui/text-base/text-base.ios.ts | 10 +++++----- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/tns-core-modules/ui/editable-text-base/editable-text-base-common.ts b/tns-core-modules/ui/editable-text-base/editable-text-base-common.ts index 495df9f91..2f2c94561 100644 --- a/tns-core-modules/ui/editable-text-base/editable-text-base-common.ts +++ b/tns-core-modules/ui/editable-text-base/editable-text-base-common.ts @@ -1,5 +1,5 @@ import { EditableTextBase as EditableTextBaseDefinition, KeyboardType, ReturnKeyType, UpdateTextTrigger, AutocapitalizationType } from "."; -import { TextBase, Property, CssProperty, Style, Color, booleanConverter, makeValidator, makeParser } from "../text-base"; +import { TextBase, Property, CssProperty, Style, Color, booleanConverter, makeValidator, makeParser, resetSymbol } from "../text-base"; export * from "../text-base"; 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 edacc4fc2..c4c0a999e 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 @@ -1,7 +1,7 @@ import { EditableTextBase as EditableTextBaseCommon, keyboardTypeProperty, returnKeyTypeProperty, editableProperty, - autocapitalizationTypeProperty, autocorrectProperty, hintProperty, + autocapitalizationTypeProperty, autocorrectProperty, hintProperty, resetSymbol, textProperty, placeholderColorProperty, Color, textTransformProperty, maxLengthProperty } from "./editable-text-base-common"; @@ -241,13 +241,13 @@ export abstract class EditableTextBase extends EditableTextBaseCommon { } } - [textProperty.getDefault](): number { - return -1; + [textProperty.getDefault](): number | symbol { + return resetSymbol; } - [textProperty.setNative](value: string | number) { + [textProperty.setNative](value: string | number | symbol) { try { this._changeFromCode = true; - this._setNativeText(value === -1); + this._setNativeText(value === resetSymbol); } finally { this._changeFromCode = false; } 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 65dc9418b..5583a0cd9 100644 --- a/tns-core-modules/ui/text-base/text-base-common.ts +++ b/tns-core-modules/ui/text-base/text-base-common.ts @@ -213,3 +213,5 @@ letterSpacingProperty.register(Style); export const lineHeightProperty = new CssProperty({ name: "lineHeight", cssName: "line-height", affectsLayout: isIOS, valueConverter: v => parseFloat(v) }); lineHeightProperty.register(Style); + +export const resetSymbol = Symbol("textPropertyDefault"); \ No newline at end of file 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 50c225a58..3540170c5 100644 --- a/tns-core-modules/ui/text-base/text-base.android.ts +++ b/tns-core-modules/ui/text-base/text-base.android.ts @@ -5,7 +5,7 @@ import { TextBaseCommon, formattedTextProperty, textAlignmentProperty, textDecorationProperty, fontSizeProperty, textProperty, textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty, paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, Length, - whiteSpaceProperty, lineHeightProperty, FormattedString, layout, Span, Color, isBold + whiteSpaceProperty, lineHeightProperty, FormattedString, layout, Span, Color, isBold, resetSymbol } from "./text-base-common"; export * from "./text-base-common"; @@ -97,12 +97,12 @@ export class TextBase extends TextBaseCommon { this._maxHeight = this._maxLines = undefined; } - [textProperty.getDefault](): number { - return -1; + [textProperty.getDefault](): symbol | number { + return resetSymbol; } - [textProperty.setNative](value: string | number) { - const reset = value === -1; + [textProperty.setNative](value: string | number | symbol) { + const reset = value === resetSymbol; if (!reset && this.formattedText) { return; } diff --git a/tns-core-modules/ui/text-base/text-base.d.ts b/tns-core-modules/ui/text-base/text-base.d.ts index b852c45f8..002e078dd 100644 --- a/tns-core-modules/ui/text-base/text-base.d.ts +++ b/tns-core-modules/ui/text-base/text-base.d.ts @@ -123,3 +123,5 @@ export const letterSpacingProperty: CssProperty; //Used by tab view export function getTransformedText(text: string, textTransform: TextTransform): string; + +export const resetSymbol: symbol; 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 e2a966c66..350522a89 100644 --- a/tns-core-modules/ui/text-base/text-base.ios.ts +++ b/tns-core-modules/ui/text-base/text-base.ios.ts @@ -3,7 +3,7 @@ import { Font } from "../styling/font"; import { TextBaseCommon, textProperty, formattedTextProperty, textAlignmentProperty, textDecorationProperty, textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty, lineHeightProperty, - FormattedString, Span, Color, isBold + FormattedString, Span, Color, isBold, resetSymbol } from "./text-base-common"; export * from "./text-base-common"; @@ -12,11 +12,11 @@ export class TextBase extends TextBaseCommon { public nativeViewProtected: UITextField | UITextView | UILabel | UIButton; - [textProperty.getDefault](): number { - return -1; + [textProperty.getDefault](): number | symbol { + return resetSymbol; } - [textProperty.setNative](value: string | number) { - const reset = value === -1; + [textProperty.setNative](value: string | number | symbol) { + const reset = value === resetSymbol; if (!reset && this.formattedText) { return; }