Skip to content

Commit 04aa2ba

Browse files
authored
fix(core): corrected background color between Label and nested spans (NativeScript#10701)
1 parent 70e7248 commit 04aa2ba

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
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,8 +394,9 @@ 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+
// Use span or formatted string color
398+
const backgroundColor = span.style.backgroundColor || span.parent.backgroundColor;
397399

398-
const backgroundColor = <Color>(span.style.backgroundColor || (<FormattedString>span.parent).backgroundColor || (<TextBase>span.parent.parent).backgroundColor);
399400
return {
400401
text,
401402
iosFont,

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
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+
/**
14+
* String value used when hooking to linkTap event.
15+
*
16+
* @nsEvent linkTap
17+
*/
18+
public static linkTapEvent: string;
19+
20+
declare parent: FormattedString;
21+
1222
/**
1323
* Gets or sets the font family of the span.
1424
*
@@ -92,12 +102,6 @@ export class Span extends ViewBase {
92102
* @nsProperty
93103
*/
94104
public text: string;
95-
/**
96-
* String value used when hooking to linkTap event.
97-
*
98-
* @nsEvent linkTap
99-
*/
100-
public static linkTapEvent: string;
101105

102106
/**
103107
* Gets if the span is tappable or not.

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)