Skip to content

Commit 7cd8e7e

Browse files
shiv19Alexander Vakrilov
authored andcommitted
fix(text): Allow -1 to be a valid binding value for text views (NativeScript#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 NativeScript#5559 * renamed the symbol
1 parent 4b24492 commit 7cd8e7e

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

tns-core-modules/ui/editable-text-base/editable-text-base-common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EditableTextBase as EditableTextBaseDefinition, KeyboardType, ReturnKeyType, UpdateTextTrigger, AutocapitalizationType } from ".";
2-
import { TextBase, Property, CssProperty, Style, Color, booleanConverter, makeValidator, makeParser } from "../text-base";
2+
import { TextBase, Property, CssProperty, Style, Color, booleanConverter, makeValidator, makeParser, resetSymbol } from "../text-base";
33

44
export * from "../text-base";
55

tns-core-modules/ui/editable-text-base/editable-text-base.android.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
EditableTextBase as EditableTextBaseCommon, keyboardTypeProperty,
33
returnKeyTypeProperty, editableProperty,
4-
autocapitalizationTypeProperty, autocorrectProperty, hintProperty,
4+
autocapitalizationTypeProperty, autocorrectProperty, hintProperty, resetSymbol,
55
textProperty, placeholderColorProperty, Color, textTransformProperty, maxLengthProperty
66
} from "./editable-text-base-common";
77

@@ -241,13 +241,13 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
241241
}
242242
}
243243

244-
[textProperty.getDefault](): number {
245-
return -1;
244+
[textProperty.getDefault](): number | symbol {
245+
return resetSymbol;
246246
}
247-
[textProperty.setNative](value: string | number) {
247+
[textProperty.setNative](value: string | number | symbol) {
248248
try {
249249
this._changeFromCode = true;
250-
this._setNativeText(value === -1);
250+
this._setNativeText(value === resetSymbol);
251251
} finally {
252252
this._changeFromCode = false;
253253
}

tns-core-modules/ui/text-base/text-base-common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,5 @@ letterSpacingProperty.register(Style);
213213

214214
export const lineHeightProperty = new CssProperty<Style, number>({ name: "lineHeight", cssName: "line-height", affectsLayout: isIOS, valueConverter: v => parseFloat(v) });
215215
lineHeightProperty.register(Style);
216+
217+
export const resetSymbol = Symbol("textPropertyDefault");

tns-core-modules/ui/text-base/text-base.android.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
TextBaseCommon, formattedTextProperty, textAlignmentProperty, textDecorationProperty, fontSizeProperty,
66
textProperty, textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty,
77
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, Length,
8-
whiteSpaceProperty, lineHeightProperty, FormattedString, layout, Span, Color, isBold
8+
whiteSpaceProperty, lineHeightProperty, FormattedString, layout, Span, Color, isBold, resetSymbol
99
} from "./text-base-common";
1010

1111
export * from "./text-base-common";
@@ -97,12 +97,12 @@ export class TextBase extends TextBaseCommon {
9797
this._maxHeight = this._maxLines = undefined;
9898
}
9999

100-
[textProperty.getDefault](): number {
101-
return -1;
100+
[textProperty.getDefault](): symbol | number {
101+
return resetSymbol;
102102
}
103103

104-
[textProperty.setNative](value: string | number) {
105-
const reset = value === -1;
104+
[textProperty.setNative](value: string | number | symbol) {
105+
const reset = value === resetSymbol;
106106
if (!reset && this.formattedText) {
107107
return;
108108
}

tns-core-modules/ui/text-base/text-base.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,5 @@ export const letterSpacingProperty: CssProperty<Style, number>;
123123

124124
//Used by tab view
125125
export function getTransformedText(text: string, textTransform: TextTransform): string;
126+
127+
export const resetSymbol: symbol;

tns-core-modules/ui/text-base/text-base.ios.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Font } from "../styling/font";
33
import {
44
TextBaseCommon, textProperty, formattedTextProperty, textAlignmentProperty, textDecorationProperty,
55
textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty, lineHeightProperty,
6-
FormattedString, Span, Color, isBold
6+
FormattedString, Span, Color, isBold, resetSymbol
77
} from "./text-base-common";
88

99
export * from "./text-base-common";
@@ -12,11 +12,11 @@ export class TextBase extends TextBaseCommon {
1212

1313
public nativeViewProtected: UITextField | UITextView | UILabel | UIButton;
1414

15-
[textProperty.getDefault](): number {
16-
return -1;
15+
[textProperty.getDefault](): number | symbol {
16+
return resetSymbol;
1717
}
18-
[textProperty.setNative](value: string | number) {
19-
const reset = value === -1;
18+
[textProperty.setNative](value: string | number | symbol) {
19+
const reset = value === resetSymbol;
2020
if (!reset && this.formattedText) {
2121
return;
2222
}

0 commit comments

Comments
 (0)