mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(text): crash when removing FormattedText (#7237)
* fix(text): crash when removing FormattedText * refactor: fixed crash on ios too
This commit is contained in:
committed by
GitHub
parent
c85f3232dc
commit
37b53c6030
@@ -162,10 +162,10 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
||||
const span = new Span();
|
||||
span.text = "long label";
|
||||
span.fontWeight = "bold";
|
||||
|
||||
|
||||
const span2 = new Span();
|
||||
span2.text = "long label";
|
||||
|
||||
|
||||
const formattedString = new FormattedString();
|
||||
formattedString.spans.push(span);
|
||||
formattedString.spans.push(span2);
|
||||
@@ -176,7 +176,7 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
||||
const span3 = new Span();
|
||||
span3.text = "short label";
|
||||
span3.fontWeight = "bold";
|
||||
|
||||
|
||||
const formattedString2 = new FormattedString();
|
||||
formattedString2.spans.push(span3);
|
||||
label.formattedText = formattedString2;
|
||||
@@ -210,7 +210,7 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
||||
const span = new Span();
|
||||
span.text = "short label";
|
||||
span.fontWeight = "bold";
|
||||
|
||||
|
||||
const formattedString = new FormattedString();
|
||||
formattedString.spans.push(span);
|
||||
label.formattedText = formattedString;
|
||||
@@ -220,10 +220,10 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
||||
const span2 = new Span();
|
||||
span2.text = "long label";
|
||||
span2.fontWeight = "bold";
|
||||
|
||||
|
||||
const span3 = new Span();
|
||||
span3.text = "long label";
|
||||
|
||||
|
||||
const formattedString2 = new FormattedString();
|
||||
formattedString2.spans.push(span2);
|
||||
formattedString2.spans.push(span3);
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user