fix(text): crash when removing FormattedText (#7237)

* fix(text): crash when removing FormattedText

* refactor: fixed crash on ios too
This commit is contained in:
Alexander Vakrilov
2019-05-13 17:03:46 +03:00
committed by GitHub
parent c85f3232dc
commit 37b53c6030
3 changed files with 24 additions and 9 deletions

View File

@@ -733,6 +733,21 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
return host;
});
}
public test_FormattedText_ShouldNotCrash_WheRemovedFromSpan() {
const label = this.testView;
label.color = new colorModule.Color("red");
this.waitUntilTestElementIsLoaded();
const span = new Span();
span.text = "test";
const formattedString = new FormattedString();
formattedString.spans.push(span);
label._addChildFromBuilder("FormattedString", formattedString);
label._removeView(formattedString);
};
}
export function createTestCase(): LabelTest {

View File

@@ -12,7 +12,7 @@ import { isString } from "../../utils/types";
export * from "./text-base-common";
interface TextTransformation {
new (owner: TextBase): android.text.method.TransformationMethod;
new(owner: TextBase): android.text.method.TransformationMethod;
}
let TextTransformation: TextTransformation;
@@ -344,7 +344,7 @@ export function getTransformedText(text: string, textTransform: TextTransform):
}
function createSpannableStringBuilder(formattedString: FormattedString): android.text.SpannableStringBuilder {
if (!formattedString) {
if (!formattedString || !formattedString.parent) {
return null;
}

View File

@@ -231,7 +231,7 @@ export class TextBase extends TextBaseCommon {
createNSMutableAttributedString(formattedString: FormattedString): NSMutableAttributedString {
let mas = NSMutableAttributedString.alloc().init();
if (formattedString) {
if (formattedString && formattedString.parent) {
for (let i = 0, spanStart = 0, length = formattedString.spans.length; i < length; i++) {
const span = formattedString.spans.getItem(i);
const text = span.text;