mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
feat(text-base): allow subclass to override createFormattedTextNative (#9334)
This commit is contained in:
@ -40,7 +40,7 @@ function initializeTextTransformation(): void {
|
|||||||
// NOTE: Do we need to transform the new text here?
|
// NOTE: Do we need to transform the new text here?
|
||||||
const formattedText = this.textBase.formattedText;
|
const formattedText = this.textBase.formattedText;
|
||||||
if (formattedText) {
|
if (formattedText) {
|
||||||
return createSpannableStringBuilder(formattedText, (<android.widget.TextView>view).getTextSize());
|
return this.textBase.createFormattedTextNative(formattedText);
|
||||||
} else {
|
} else {
|
||||||
const text = this.textBase.text;
|
const text = this.textBase.text;
|
||||||
const stringValue = isNullOrUndefined(text) ? '' : text.toString();
|
const stringValue = isNullOrUndefined(text) ? '' : text.toString();
|
||||||
@ -233,7 +233,9 @@ export class TextBase extends TextBaseCommon {
|
|||||||
|
|
||||||
this._setNativeText(reset);
|
this._setNativeText(reset);
|
||||||
}
|
}
|
||||||
|
createFormattedTextNative(value: FormattedString) {
|
||||||
|
return createSpannableStringBuilder(value, this.style.fontSize);
|
||||||
|
}
|
||||||
[formattedTextProperty.setNative](value: FormattedString) {
|
[formattedTextProperty.setNative](value: FormattedString) {
|
||||||
const nativeView = this.nativeTextViewProtected;
|
const nativeView = this.nativeTextViewProtected;
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@ -247,7 +249,7 @@ export class TextBase extends TextBaseCommon {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const spannableStringBuilder = createSpannableStringBuilder(value, this.style.fontSize);
|
const spannableStringBuilder = this.createFormattedTextNative(value);
|
||||||
nativeView.setText(<any>spannableStringBuilder);
|
nativeView.setText(<any>spannableStringBuilder);
|
||||||
this._setTappableState(isStringTappable(value));
|
this._setTappableState(isStringTappable(value));
|
||||||
|
|
||||||
@ -443,7 +445,7 @@ export class TextBase extends TextBaseCommon {
|
|||||||
|
|
||||||
let transformedText: any;
|
let transformedText: any;
|
||||||
if (this.formattedText) {
|
if (this.formattedText) {
|
||||||
transformedText = createSpannableStringBuilder(this.formattedText, this.style.fontSize);
|
transformedText = this.createFormattedTextNative(this.formattedText);
|
||||||
} else {
|
} else {
|
||||||
const text = this.text;
|
const text = this.text;
|
||||||
const stringValue = text === null || text === undefined ? '' : text.toString();
|
const stringValue = text === null || text === undefined ? '' : text.toString();
|
||||||
|
@ -226,8 +226,11 @@ export class TextBase extends TextBaseCommon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createFormattedTextNative(value: FormattedString) {
|
||||||
|
return this.createNSMutableAttributedString(value);
|
||||||
|
}
|
||||||
setFormattedTextDecorationAndTransform() {
|
setFormattedTextDecorationAndTransform() {
|
||||||
const attrText = this.createNSMutableAttributedString(this.formattedText);
|
const attrText = this.createFormattedTextNative(this.formattedText);
|
||||||
// TODO: letterSpacing should be applied per Span.
|
// TODO: letterSpacing should be applied per Span.
|
||||||
if (this.letterSpacing !== 0) {
|
if (this.letterSpacing !== 0) {
|
||||||
attrText.addAttributeValueRange(NSKernAttributeName, this.letterSpacing * this.nativeTextViewProtected.font.pointSize, { location: 0, length: attrText.length });
|
attrText.addAttributeValueRange(NSKernAttributeName, this.letterSpacing * this.nativeTextViewProtected.font.pointSize, { location: 0, length: attrText.length });
|
||||||
|
Reference in New Issue
Block a user