MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / setSpanModifiers

Function setSpanModifiers

packages/core/ui/text-base/index.android.ts:635–688  ·  view source on GitHub ↗
(ssb: android.text.SpannableStringBuilder, span: Span, start: number, end: number, defaultFontSize: number)

Source from the content-addressed store, hash-verified

633}
634
635function setSpanModifiers(ssb: android.text.SpannableStringBuilder, span: Span, start: number, end: number, defaultFontSize: number): void {
636 const spanStyle = span.style;
637 const align = spanStyle.verticalAlignment;
638
639 const font = new Font(spanStyle.fontFamily, spanStyle.fontSize, spanStyle.fontStyle, spanStyle.fontWeight, spanStyle.fontScaleInternal, spanStyle.fontVariationSettings);
640 const typefaceSpan = new org.nativescript.widgets.CustomTypefaceSpan(font.getAndroidTypeface());
641 ssb.setSpan(typefaceSpan, start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
642
643 if (spanStyle.fontSize) {
644 ssb.setSpan(new android.text.style.AbsoluteSizeSpan(layout.toDevicePixels(spanStyle.fontSize)), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
645 }
646
647 const color = spanStyle.color;
648 if (color) {
649 ssb.setSpan(new android.text.style.ForegroundColorSpan(color.android), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
650 }
651
652 // Use span or formatted string color
653 const backgroundColor = spanStyle.backgroundColor || span.parent.backgroundColor;
654 if (backgroundColor) {
655 ssb.setSpan(new android.text.style.BackgroundColorSpan(backgroundColor.android), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
656 }
657
658 const textDecoration: CoreTypes.TextDecorationType = getClosestPropertyValue(textDecorationProperty, span);
659
660 if (textDecoration) {
661 const underline = textDecoration.indexOf('underline') !== -1;
662 if (underline) {
663 ssb.setSpan(new android.text.style.UnderlineSpan(), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
664 }
665
666 const strikethrough = textDecoration.indexOf('line-through') !== -1;
667 if (strikethrough) {
668 ssb.setSpan(new android.text.style.StrikethroughSpan(), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
669 }
670 }
671
672 if (align) {
673 initializeBaselineAdjustedSpan();
674 ssb.setSpan(new BaselineAdjustedSpan(layout.toDevicePixels(defaultFontSize), align), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
675 }
676
677 const tappable = span.tappable;
678 if (tappable) {
679 initializeClickableSpan();
680 ssb.setSpan(new ClickableSpan(span), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
681 }
682
683 // TODO: Implement letterSpacing for Span here.
684 // const letterSpacing = formattedString.parent.style.letterSpacing;
685 // if (letterSpacing > 0) {
686 // ssb.setSpan(new android.text.style.ScaleXSpan((letterSpacing + 1) / 10), start, end, android.text.Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
687 // }
688}

Callers 1

Calls 5

getAndroidTypefaceMethod · 0.95
getClosestPropertyValueFunction · 0.90
initializeClickableSpanFunction · 0.85
indexOfMethod · 0.80

Tested by

no test coverage detected