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:
@ -78,7 +78,7 @@ var _createButtonFunc = function (): buttonModule.Button {
|
|||||||
// >>button-create
|
// >>button-create
|
||||||
var button = new buttonModule.Button();
|
var button = new buttonModule.Button();
|
||||||
// << button-create
|
// << button-create
|
||||||
button.text = "Button";
|
button.text = "Button";
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,3 +372,21 @@ export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedT
|
|||||||
TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
|
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": {
|
"nativescript": {
|
||||||
"id": "org.nativescript.tests",
|
"id": "org.nativescript.tests",
|
||||||
"tns-ios": {
|
"tns-ios": {
|
||||||
"version": "2.5.0"
|
"version": "3.0.0"
|
||||||
},
|
},
|
||||||
"tns-android": {
|
"tns-android": {
|
||||||
"version": "2.5.0"
|
"version": "3.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -320,7 +320,8 @@ function setSpanModifiers(ssb: android.text.SpannableStringBuilder, span: Span,
|
|||||||
const fontFamily = span.fontFamily;
|
const fontFamily = span.fontFamily;
|
||||||
if (fontFamily) {
|
if (fontFamily) {
|
||||||
const font = new Font(fontFamily, 0, (italic) ? "italic" : "normal", (bold) ? "bold" : "normal");
|
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);
|
ssb.setSpan(typefaceSpan, start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user