Skip to content

Commit

Permalink
fix(text): Allow -1 to be a valid binding value for text views (#5563)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
shiv19 authored and Alexander Vakrilov committed Mar 21, 2018
1 parent 4b24492 commit 7cd8e7e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
@@ -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";

Expand Down
@@ -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";

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions tns-core-modules/ui/text-base/text-base-common.ts
Expand Up @@ -213,3 +213,5 @@ letterSpacingProperty.register(Style);

export const lineHeightProperty = new CssProperty<Style, number>({ name: "lineHeight", cssName: "line-height", affectsLayout: isIOS, valueConverter: v => parseFloat(v) });
lineHeightProperty.register(Style);

export const resetSymbol = Symbol("textPropertyDefault");
10 changes: 5 additions & 5 deletions tns-core-modules/ui/text-base/text-base.android.ts
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions tns-core-modules/ui/text-base/text-base.d.ts
Expand Up @@ -123,3 +123,5 @@ export const letterSpacingProperty: CssProperty<Style, number>;

//Used by tab view
export function getTransformedText(text: string, textTransform: TextTransform): string;

export const resetSymbol: symbol;
10 changes: 5 additions & 5 deletions tns-core-modules/ui/text-base/text-base.ios.ts
Expand Up @@ -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";
Expand All @@ -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;
}
Expand Down

0 comments on commit 7cd8e7e

Please sign in to comment.