Skip to content

Commit b12c28d

Browse files
committed
fix: Use FormattedString background color as fallback
1 parent 333086d commit b12c28d

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,10 @@ function setSpanModifiers(ssb: android.text.SpannableStringBuilder, span: Span,
624624
ssb.setSpan(new android.text.style.ForegroundColorSpan(color.android), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
625625
}
626626

627-
if (spanStyle.backgroundColor) {
628-
ssb.setSpan(new android.text.style.BackgroundColorSpan(spanStyle.backgroundColor.android), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
627+
// Use span or formatted string color
628+
const backgroundColor = spanStyle.backgroundColor || span.parent.backgroundColor;
629+
if (backgroundColor) {
630+
ssb.setSpan(new android.text.style.BackgroundColorSpan(backgroundColor.android), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
629631
}
630632

631633
const textDecoration: CoreTypes.TextDecorationType = getClosestPropertyValue(textDecorationProperty, span);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ export class TextBase extends TextBaseCommon {
394394
const fontScale = adjustMinMaxFontScale(span.style.fontScaleInternal, span);
395395
const font = new Font(span.style.fontFamily, span.style.fontSize, span.style.fontStyle, span.style.fontWeight, fontScale, span.style.fontVariationSettings);
396396
const iosFont = font.getUIFont(this.nativeTextViewProtected.font);
397-
const backgroundColor = span.style.backgroundColor;
397+
// Use span or formatted string color
398+
const backgroundColor = span.style.backgroundColor || span.parent.backgroundColor;
398399

399400
return {
400401
text,

packages/core/ui/text-base/span.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
import { ViewBase } from '../core/view-base';
33
import { FontStyleType, FontVariationSettingsType, FontWeightType } from '../styling/font';
44
import { CoreTypes } from '../../core-types';
5+
import { FormattedString } from './formatted-string';
56

67
/**
78
* A class used to create a single part of formatted string with a common text properties.
89
*
910
* @nsView Span
1011
*/
1112
export class Span extends ViewBase {
13+
declare parent: FormattedString;
14+
1215
/**
1316
* Gets or sets the font family of the span.
1417
*

packages/core/ui/text-base/span.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import { FontStyleType, FontVariationSettingsType, FontWeightType } from '../sty
55
import { CoreTypes } from '../../core-types';
66
import { EventData } from '../../data/observable';
77
import { isNullOrUndefined, isString } from '../../utils/types';
8+
import type { FormattedString } from './formatted-string';
89

910
export class Span extends ViewBase implements SpanDefinition {
10-
static linkTapEvent = 'linkTap';
11+
public static linkTapEvent = 'linkTap';
12+
1113
private _text: string;
1214
private _tappable = false;
1315

16+
declare parent: FormattedString;
17+
1418
get fontFamily(): string {
1519
return this.style.fontFamily;
1620
}

0 commit comments

Comments
 (0)