chore: cleanup

This commit is contained in:
Nathan Walker
2020-07-09 23:43:28 -07:00
parent 0ae8dba962
commit 8100cf7089
89 changed files with 493 additions and 704 deletions

View File

@@ -10,7 +10,7 @@ import { colorProperty, fontSizeProperty, fontInternalProperty, paddingLeftPrope
import { FormattedString } from './formatted-string';
import { Span } from './span';
import { layout } from '../../utils';
import { isString } from '../../utils/types';
import { isString, isNullOrUndefined } from '../../utils/types';
export * from './text-base-common';
@@ -40,7 +40,7 @@ function initializeTextTransformation(): void {
return createSpannableStringBuilder(formattedText, (<android.widget.TextView>view).getTextSize());
} else {
const text = this.textBase.text;
const stringValue = text === null || text === undefined ? '' : text.toString();
const stringValue = isNullOrUndefined(text) ? '' : text.toString();
return getTransformedText(stringValue, this.textBase.textTransform);
}

View File

@@ -8,7 +8,7 @@ import { Color } from '../../color';
import { FormattedString } from './formatted-string';
import { Span } from './span';
import { colorProperty, fontInternalProperty, VerticalAlignment } from '../styling/style-properties';
import { isString } from '../../utils/types';
import { isString, isDefined, isNullOrUndefined } from '../../utils/types';
import { ios } from '../../utils';
export * from './text-base-common';
@@ -307,7 +307,7 @@ export class TextBase extends TextBaseCommon {
dict.set(NSParagraphStyleAttributeName, paragraphStyle);
}
const source = getTransformedText(this.text ? this.text.toString() : '', this.textTransform);
const source = getTransformedText(isNullOrUndefined(this.text) ? '' : `${this.text}`, this.textTransform);
if (dict.size > 0 || isTextView) {
if (isTextView && this.nativeTextViewProtected.font) {
// UITextView's font seems to change inside.
@@ -349,7 +349,7 @@ export class TextBase extends TextBaseCommon {
const span = formattedString.spans.getItem(i);
const text = span.text;
const textTransform = (<TextBase>formattedString.parent).textTransform;
let spanText = text === null || text === undefined ? '' : text.toString();
let spanText = isNullOrUndefined(text) ? '' : `${text}`;
if (textTransform !== 'none' && textTransform !== 'initial') {
spanText = getTransformedText(spanText, textTransform);
}

View File

@@ -4,6 +4,7 @@ import { ViewBase } from '../core/view-base';
import { FontStyle, FontWeight } from '../styling/font';
import { TextDecoration } from '../text-base';
import { EventData } from '../../data/observable';
import { isNullOrUndefined, isString } from '../../utils/types';
export class Span extends ViewBase implements SpanDefinition {
static linkTapEvent = 'linkTap';
@@ -66,8 +67,12 @@ export class Span extends ViewBase implements SpanDefinition {
}
set text(value: string) {
if (this._text !== value) {
// value can be a number
this._text = `${value}`.replace('\\n', '\n').replace('\\t', '\t');
if (isNullOrUndefined(value)) {
this._text = '';
} else {
// value can be a number
this._text = isString(value) ? `${value}`.replace('\\n', '\n').replace('\\t', '\t') : `${value}`;
}
this.notifyPropertyChange('text', this._text);
}
}