Skip to content

Commit b29e145

Browse files
authored
feat(text-base): allow subclass to override createFormattedTextNative (#9334)
1 parent cbdff1f commit b29e145

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎packages/core/ui/text-base/index.android.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function initializeTextTransformation(): void {
4040
// NOTE: Do we need to transform the new text here?
4141
const formattedText = this.textBase.formattedText;
4242
if (formattedText) {
43-
return createSpannableStringBuilder(formattedText, (<android.widget.TextView>view).getTextSize());
43+
return this.textBase.createFormattedTextNative(formattedText);
4444
} else {
4545
const text = this.textBase.text;
4646
const stringValue = isNullOrUndefined(text) ? '' : text.toString();
@@ -233,7 +233,9 @@ export class TextBase extends TextBaseCommon {
233233

234234
this._setNativeText(reset);
235235
}
236-
236+
createFormattedTextNative(value: FormattedString) {
237+
return createSpannableStringBuilder(value, this.style.fontSize);
238+
}
237239
[formattedTextProperty.setNative](value: FormattedString) {
238240
const nativeView = this.nativeTextViewProtected;
239241
if (!value) {
@@ -247,7 +249,7 @@ export class TextBase extends TextBaseCommon {
247249
return;
248250
}
249251

250-
const spannableStringBuilder = createSpannableStringBuilder(value, this.style.fontSize);
252+
const spannableStringBuilder = this.createFormattedTextNative(value);
251253
nativeView.setText(<any>spannableStringBuilder);
252254
this._setTappableState(isStringTappable(value));
253255

@@ -443,7 +445,7 @@ export class TextBase extends TextBaseCommon {
443445

444446
let transformedText: any;
445447
if (this.formattedText) {
446-
transformedText = createSpannableStringBuilder(this.formattedText, this.style.fontSize);
448+
transformedText = this.createFormattedTextNative(this.formattedText);
447449
} else {
448450
const text = this.text;
449451
const stringValue = text === null || text === undefined ? '' : text.toString();

‎packages/core/ui/text-base/index.ios.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,11 @@ export class TextBase extends TextBaseCommon {
226226
}
227227
}
228228

229+
createFormattedTextNative(value: FormattedString) {
230+
return this.createNSMutableAttributedString(value);
231+
}
229232
setFormattedTextDecorationAndTransform() {
230-
const attrText = this.createNSMutableAttributedString(this.formattedText);
233+
const attrText = this.createFormattedTextNative(this.formattedText);
231234
// TODO: letterSpacing should be applied per Span.
232235
if (this.letterSpacing !== 0) {
233236
attrText.addAttributeValueRange(NSKernAttributeName, this.letterSpacing * this.nativeTextViewProtected.font.pointSize, { location: 0, length: attrText.length });

0 commit comments

Comments
 (0)