Prevent app crash for css text-transform (#6815)

* Prevent app crash for css text-transform

* refactor: formatting

* refactor: formatting

* minor refactoring

* fix: use isString - text is sometimes String

* fix: use isString - text is sometimes String
This commit is contained in:
Jonathan Salomon
2019-02-07 10:59:53 +02:00
committed by Svetoslav
parent cea97c6b45
commit 9f8d24a811
2 changed files with 11 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import {
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, Length, paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, Length,
whiteSpaceProperty, lineHeightProperty, FormattedString, layout, Span, Color, isBold, resetSymbol whiteSpaceProperty, lineHeightProperty, FormattedString, layout, Span, Color, isBold, resetSymbol
} from "./text-base-common"; } from "./text-base-common";
import { isString } from "../../utils/types";
export * from "./text-base-common"; export * from "./text-base-common";
@ -323,6 +324,10 @@ function getCapitalizedString(str: string): string {
} }
export function getTransformedText(text: string, textTransform: TextTransform): string { export function getTransformedText(text: string, textTransform: TextTransform): string {
if (!text || !isString(text)) {
return "";
}
switch (textTransform) { switch (textTransform) {
case "uppercase": case "uppercase":
return text.toUpperCase(); return text.toUpperCase();
@ -439,4 +444,4 @@ function setSpanModifiers(ssb: android.text.SpannableStringBuilder, span: Span,
// if (letterSpacing > 0) { // if (letterSpacing > 0) {
// ssb.setSpan(new android.text.style.ScaleXSpan((letterSpacing + 1) / 10), start, end, android.text.Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // ssb.setSpan(new android.text.style.ScaleXSpan((letterSpacing + 1) / 10), start, end, android.text.Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// } // }
} }

View File

@ -5,6 +5,7 @@ import {
textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty, lineHeightProperty, textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty, lineHeightProperty,
FormattedString, Span, Color, isBold, resetSymbol FormattedString, Span, Color, isBold, resetSymbol
} from "./text-base-common"; } from "./text-base-common";
import { isString } from "../../utils/types";
export * from "./text-base-common"; export * from "./text-base-common";
@ -298,6 +299,10 @@ export class TextBase extends TextBaseCommon {
} }
export function getTransformedText(text: string, textTransform: TextTransform): string { export function getTransformedText(text: string, textTransform: TextTransform): string {
if (!text || !isString(text)) {
return "";
}
switch (textTransform) { switch (textTransform) {
case "uppercase": case "uppercase":
return NSStringFromNSAttributedString(text).uppercaseString; return NSStringFromNSAttributedString(text).uppercaseString;