mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
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
This commit is contained in:
committed by
Alexander Vakrilov
parent
4b244921d4
commit
7cd8e7ef54
@@ -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";
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
2
tns-core-modules/ui/text-base/text-base.d.ts
vendored
2
tns-core-modules/ui/text-base/text-base.d.ts
vendored
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user