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
@@ -733,6 +733,21 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
|||||||
return host;
|
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 {
|
export function createTestCase(): LabelTest {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { isString } from "../../utils/types";
|
|||||||
export * from "./text-base-common";
|
export * from "./text-base-common";
|
||||||
|
|
||||||
interface TextTransformation {
|
interface TextTransformation {
|
||||||
new (owner: TextBase): android.text.method.TransformationMethod;
|
new(owner: TextBase): android.text.method.TransformationMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
let TextTransformation: TextTransformation;
|
let TextTransformation: TextTransformation;
|
||||||
@@ -344,7 +344,7 @@ export function getTransformedText(text: string, textTransform: TextTransform):
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createSpannableStringBuilder(formattedString: FormattedString): android.text.SpannableStringBuilder {
|
function createSpannableStringBuilder(formattedString: FormattedString): android.text.SpannableStringBuilder {
|
||||||
if (!formattedString) {
|
if (!formattedString || !formattedString.parent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ export class TextBase extends TextBaseCommon {
|
|||||||
|
|
||||||
createNSMutableAttributedString(formattedString: FormattedString): NSMutableAttributedString {
|
createNSMutableAttributedString(formattedString: FormattedString): NSMutableAttributedString {
|
||||||
let mas = NSMutableAttributedString.alloc().init();
|
let mas = NSMutableAttributedString.alloc().init();
|
||||||
if (formattedString) {
|
if (formattedString && formattedString.parent) {
|
||||||
for (let i = 0, spanStart = 0, length = formattedString.spans.length; i < length; i++) {
|
for (let i = 0, spanStart = 0, length = formattedString.spans.length; i < length; i++) {
|
||||||
const span = formattedString.spans.getItem(i);
|
const span = formattedString.spans.getItem(i);
|
||||||
const text = span.text;
|
const text = span.text;
|
||||||
|
|||||||
Reference in New Issue
Block a user