mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
FIX: Span with unknown font-family crash
This commit is contained in:
@ -372,3 +372,21 @@ export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedT
|
||||
TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
|
||||
});
|
||||
}
|
||||
|
||||
// Reported in https://github.com/NativeScript/NativeScript/issues/4109
|
||||
export function test_setting_formattedText_With_UnknownFont_DoesNotCrash() {
|
||||
let btn = new buttonModule.Button();
|
||||
btn.style.fontFamily = "_UnknownFont";
|
||||
|
||||
helper.buildUIAndRunTest(btn, function (views) {
|
||||
TKUnit.waitUntilReady(() => { return btn.isLayoutValid; });
|
||||
|
||||
let span = new spanModule.Span();
|
||||
span.text = "Login";
|
||||
let formattedString = new formattedStringModule.FormattedString();
|
||||
formattedString.spans.push(span);
|
||||
btn.formattedText = formattedString;
|
||||
|
||||
TKUnit.waitUntilReady(() => { return btn.isLayoutValid; });
|
||||
});
|
||||
}
|
||||
|
@ -6,10 +6,10 @@
|
||||
"nativescript": {
|
||||
"id": "org.nativescript.tests",
|
||||
"tns-ios": {
|
||||
"version": "2.5.0"
|
||||
"version": "3.0.0"
|
||||
},
|
||||
"tns-android": {
|
||||
"version": "2.5.0"
|
||||
"version": "3.0.0"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -320,7 +320,8 @@ function setSpanModifiers(ssb: android.text.SpannableStringBuilder, span: Span,
|
||||
const fontFamily = span.fontFamily;
|
||||
if (fontFamily) {
|
||||
const font = new Font(fontFamily, 0, (italic) ? "italic" : "normal", (bold) ? "bold" : "normal");
|
||||
const typefaceSpan: android.text.style.TypefaceSpan = new org.nativescript.widgets.CustomTypefaceSpan(fontFamily, font.getAndroidTypeface());
|
||||
const typeface = font.getAndroidTypeface() || android.graphics.Typeface.create(fontFamily, 0);
|
||||
const typefaceSpan: android.text.style.TypefaceSpan = new org.nativescript.widgets.CustomTypefaceSpan(fontFamily, typeface);
|
||||
ssb.setSpan(typefaceSpan, start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user