Skip to content

Commit 740478f

Browse files
author
farfromrefuge
committed
fix: allow native attributed string (NSAttributedString and android.text.Spannable) to be used as text
1 parent 51fed69 commit 740478f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Diff for: src/label.android.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ abstract class LabelBase extends View implements LabelViewDefinition {
121121

122122
public mIsSingleLine: boolean;
123123

124-
public text: string;
124+
//@ts-ignore
125+
public text: string | java.lang.CharSequence | android.text.Spannable;
125126
//@ts-ignore
126127
formattedText: FormattedString;
127128

@@ -369,7 +370,7 @@ export class Label extends LabelBase {
369370
if (typeof value === 'number') {
370371
this.nativeTextViewProtected.setTextSize(value);
371372
} else {
372-
this.nativeTextViewProtected.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.nativeSize);
373+
this.nativeTextViewProtected.setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP, value.nativeSize);
373374
}
374375
if (this.mAutoFontSize) {
375376
this.enableAutoSize();
@@ -557,7 +558,6 @@ export class Label extends LabelBase {
557558
this.nativeTextViewProtected.setText(null);
558559
return;
559560
}
560-
561561
let transformedText: any = null;
562562
if (this.html) {
563563
transformedText = this.createHTMLString();
@@ -568,6 +568,8 @@ export class Label extends LabelBase {
568568
this,
569569
this.formattedText === null || this.formattedText === undefined ? '' : this.formattedText.toString()
570570
);
571+
} else if (this.text instanceof java.lang.CharSequence || this.text instanceof android.text.Spannable) {
572+
transformedText = this.text;
571573
} else {
572574
const text = this.text;
573575
const stringValue = text === null || text === undefined ? '' : text.toString();

Diff for: src/label.ios.ts

+5
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ export class Label extends LabelBase {
188188

189189
isUsingNSTextView = false;
190190

191+
//@ts-ignore
192+
public text: string | NSAttributedString;
193+
191194
@profile
192195
public createNativeView() {
193196
if (this.selectable) {
@@ -705,6 +708,8 @@ export class Label extends LabelBase {
705708
this.fontSizeRatio = 1;
706709
if (this.html) {
707710
this.updateHTMLString();
711+
} else if (this.text instanceof NSAttributedString) {
712+
this.nativeViewProtected.attributedText = this.text;
708713
} else {
709714
super._setNativeText();
710715
}

0 commit comments

Comments
 (0)